Skip to content

Commit 538046c

Browse files
ricardohbinbtford
authored andcommitted
fix($httpBackend): set headers even if they have falsy values
Closes angular#2984
1 parent 0d0330a commit 538046c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-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

+11
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ 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, {'X-header1': 0, 'X-header2': '', 'X-header3': false});
106+
xhr = MockXhr.$$lastInstance;
107+
108+
expect(xhr.$$reqHeaders).toEqual({
109+
'X-header1': 0,
110+
'X-header2': '',
111+
'X-header3': false
112+
});
113+
});
104114

105115
it('should abort request on timeout', function() {
106116
callback.andCallFake(function(status, response) {
@@ -388,6 +398,7 @@ describe('$httpBackend', function() {
388398
expect(callback).toHaveBeenCalled();
389399
expect(callback.mostRecentCall.args[0]).toBe(404);
390400
});
401+
391402
});
392403
});
393404

0 commit comments

Comments
 (0)