Skip to content

Commit 172a409

Browse files
perekIgorMinar
perek
authored andcommitted
fix($http) - add ability to remove default headers
Fixes angular#5784 Closes angular#5785
1 parent 23e5109 commit 172a409

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/ng/http.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,6 @@ function $HttpProvider() {
777777

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

780-
// execute if header value is function
781-
execHeaders(defHeaders);
782-
execHeaders(reqHeaders);
783-
784780
// using for-in instead of forEach to avoid unecessary iteration after header has been found
785781
defaultHeadersIteration:
786782
for (defHeaderName in defHeaders) {
@@ -795,6 +791,8 @@ function $HttpProvider() {
795791
reqHeaders[defHeaderName] = defHeaders[defHeaderName];
796792
}
797793

794+
// execute if header value is a function for merged headers
795+
execHeaders(reqHeaders);
798796
return reqHeaders;
799797

800798
function execHeaders(headers) {

test/ng/httpSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,18 @@ describe('$http', function() {
772772
$httpBackend.flush();
773773
});
774774

775+
it('should delete default headers if custom header function returns null', function () {
776+
777+
$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
778+
return !('Accept' in headers);
779+
}).respond('');
780+
781+
$http({url: '/url', method: 'POST', data: 'messageBody', headers: {
782+
'Accept': function() { return null; }
783+
}});
784+
$httpBackend.flush();
785+
});
786+
775787
it('should override default headers with custom in a case insensitive manner', function() {
776788
$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
777789
return headers['accept'] == 'Rewritten' &&

0 commit comments

Comments
 (0)