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

Commit

Permalink
fix($httpBackend): set headers with falsy values
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ricardohbin authored and btford committed Oct 1, 2013
1 parent 9361010 commit e9a2224
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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
17 changes: 17 additions & 0 deletions test/ng/httpBackendSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -388,6 +404,7 @@ describe('$httpBackend', function() {
expect(callback).toHaveBeenCalled();
expect(callback.mostRecentCall.args[0]).toBe(404);
});

});
});

0 comments on commit e9a2224

Please sign in to comment.