diff --git a/src/ng/httpBackend.js b/src/ng/httpBackend.js index 99da6549ac08..3e7406b0fde7 100644 --- a/src/ng/httpBackend.js +++ b/src/ng/httpBackend.js @@ -56,7 +56,9 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument, var xhr = new XHR(); xhr.open(method, url, true); forEach(headers, function(value, key) { - if (value) xhr.setRequestHeader(key, value); + if (isDefined(value)) { + xhr.setRequestHeader(key, value); + } }); // In IE6 and 7, this might be called synchronously when xhr.send below is called and the diff --git a/test/ng/httpBackendSpec.js b/test/ng/httpBackendSpec.js index 5d2654a9d7d7..faec5737e4c5 100644 --- a/test/ng/httpBackendSpec.js +++ b/test/ng/httpBackendSpec.js @@ -101,6 +101,22 @@ describe('$httpBackend', function() { }); }); + it('should set requested headers even if they have falsy values', function() { + $backend('POST', 'URL', null, noop, { + 'X-header1': 0, + 'X-header2': '', + 'X-header3': false, + 'X-header4': undefined + }); + + xhr = MockXhr.$$lastInstance; + + expect(xhr.$$reqHeaders).toEqual({ + 'X-header1': 0, + 'X-header2': '', + 'X-header3': false + }); + }); it('should abort request on timeout', function() { callback.andCallFake(function(status, response) { @@ -388,6 +404,7 @@ describe('$httpBackend', function() { expect(callback).toHaveBeenCalled(); expect(callback.mostRecentCall.args[0]).toBe(404); }); + }); });