Skip to content

Commit

Permalink
fix($httpBackend): don't send empty string bodies
Browse files Browse the repository at this point in the history
The `XMLHttpRequest.send` spec defines different semantics for `null`
than for an empty String: an empty String should be sent with a
`Content-Type` of `text/plain`, whereas `null` should have no
`Content-Type` header set.

Closes angular#2149
  • Loading branch information
jroper authored and jamesdaily committed Jan 27, 2014
1 parent fac2633 commit 6690316
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
xhr.responseType = responseType;
}

xhr.send(post || '');
xhr.send(post || null);
}

if (timeout > 0) {
Expand Down
6 changes: 6 additions & 0 deletions test/ng/httpBackendSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ describe('$httpBackend', function() {
expect(xhr.$$async).toBe(true);
});

it('should pass null to send if no body is set', function() {
$backend('GET', '/some-url', null, noop);
xhr = MockXhr.$$lastInstance;

expect(xhr.$$data).toBe(null);
});

it('should normalize IE\'s 1223 status code into 204', function() {
callback.andCallFake(function(status) {
Expand Down

0 comments on commit 6690316

Please sign in to comment.