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

fix($httpBackend): set headers even if they have falsy values #3857

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/ng/httpBackendSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ 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});
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) {
Expand Down Expand Up @@ -385,6 +395,7 @@ describe('$httpBackend', function() {
expect(callback).toHaveBeenCalled();
expect(callback.mostRecentCall.args[0]).toBe(404);
});

});
});