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

Commit

Permalink
fix($http) - add ability to remove default headers
Browse files Browse the repository at this point in the history
Fixes #5784
Closes #5785
  • Loading branch information
perek authored and IgorMinar committed Jul 10, 2014
1 parent 23e5109 commit 172a409
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,6 @@ function $HttpProvider() {

defHeaders = extend({}, defHeaders.common, defHeaders[lowercase(config.method)]);

// execute if header value is function
execHeaders(defHeaders);
execHeaders(reqHeaders);

// using for-in instead of forEach to avoid unecessary iteration after header has been found
defaultHeadersIteration:
for (defHeaderName in defHeaders) {
Expand All @@ -795,6 +791,8 @@ function $HttpProvider() {
reqHeaders[defHeaderName] = defHeaders[defHeaderName];
}

// execute if header value is a function for merged headers
execHeaders(reqHeaders);
return reqHeaders;

function execHeaders(headers) {
Expand Down
12 changes: 12 additions & 0 deletions test/ng/httpSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,18 @@ describe('$http', function() {
$httpBackend.flush();
});

it('should delete default headers if custom header function returns null', function () {

$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
return !('Accept' in headers);
}).respond('');

$http({url: '/url', method: 'POST', data: 'messageBody', headers: {
'Accept': function() { return null; }
}});
$httpBackend.flush();
});

it('should override default headers with custom in a case insensitive manner', function() {
$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
return headers['accept'] == 'Rewritten' &&
Expand Down

0 comments on commit 172a409

Please sign in to comment.