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 d53ab31 commit 9affbde
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
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
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 9affbde

Please sign in to comment.