From 66903165d15c89e4d2f2a9c1aef481adc2e5f7e6 Mon Sep 17 00:00:00 2001 From: James Roper Date: Tue, 17 Sep 2013 14:24:35 +1000 Subject: [PATCH] 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 --- src/ng/httpBackend.js | 2 +- test/ng/httpBackendSpec.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 371082090994..99da6549ac08 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -83,7 +83,7 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, xhr.responseType = responseType; } - xhr.send(post || ''); + xhr.send(post || null); } if (timeout > 0) { diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js index f82c175098c1..5d2654a9d7d7 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -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) {