Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 0d0330a

Browse files
jroperbtford
authored andcommitted
fix($httpBackend): don't send empty string bodies
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 #2149
1 parent 0ca5426 commit 0d0330a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/ng/httpBackend.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
8383
xhr.responseType = responseType;
8484
}
8585

86-
xhr.send(post || '');
86+
xhr.send(post || null);
8787
}
8888

8989
if (timeout > 0) {

test/ng/httpBackendSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ describe('$httpBackend', function() {
6868
expect(xhr.$$async).toBe(true);
6969
});
7070

71+
it('should pass null to send if no body is set', function() {
72+
$backend('GET', '/some-url', null, noop);
73+
xhr = MockXhr.$$lastInstance;
74+
75+
expect(xhr.$$data).toBe(null);
76+
});
7177

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

0 commit comments

Comments
 (0)