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

Commit e9a2224

Browse files
ricardohbinbtford
authored andcommitted
fix($httpBackend): set headers with falsy values
This is a breaking change. To migrate to the new behavior, delete or set headers to `undefined` to avoid having them sent. To restore the old behavior, override `$httpBackendProvider` with the old implementation. Closes #2984
1 parent 9361010 commit e9a2224

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/ng/httpBackend.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ function createHttpBackend($browser, XHR, $browserDefer, callbacks, rawDocument,
5656
var xhr = new XHR();
5757
xhr.open(method, url, true);
5858
forEach(headers, function(value, key) {
59-
if (value) xhr.setRequestHeader(key, value);
59+
if (isDefined(value)) {
60+
xhr.setRequestHeader(key, value);
61+
}
6062
});
6163

6264
// In IE6 and 7, this might be called synchronously when xhr.send below is called and the

test/ng/httpBackendSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ describe('$httpBackend', function() {
101101
});
102102
});
103103

104+
it('should set requested headers even if they have falsy values', function() {
105+
$backend('POST', 'URL', null, noop, {
106+
'X-header1': 0,
107+
'X-header2': '',
108+
'X-header3': false,
109+
'X-header4': undefined
110+
});
111+
112+
xhr = MockXhr.$$lastInstance;
113+
114+
expect(xhr.$$reqHeaders).toEqual({
115+
'X-header1': 0,
116+
'X-header2': '',
117+
'X-header3': false
118+
});
119+
});
104120

105121
it('should abort request on timeout', function() {
106122
callback.andCallFake(function(status, response) {
@@ -388,6 +404,7 @@ describe('$httpBackend', function() {
388404
expect(callback).toHaveBeenCalled();
389405
expect(callback.mostRecentCall.args[0]).toBe(404);
390406
});
407+
391408
});
392409
});
393410

0 commit comments

Comments
 (0)