Skip to content

Commit 34dcc0f

Browse files
perekIgorMinar
perek
authored andcommitted
fix($http) - add ability to remove default headers
Fixes angular#5784 Closes angular#5785
1 parent 81cd836 commit 34dcc0f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/ng/http.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,6 @@ function $HttpProvider() {
705705

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

708-
// execute if header value is function
709-
execHeaders(defHeaders);
710-
execHeaders(reqHeaders);
711-
712708
// using for-in instead of forEach to avoid unecessary iteration after header has been found
713709
defaultHeadersIteration:
714710
for (defHeaderName in defHeaders) {
@@ -723,6 +719,8 @@ function $HttpProvider() {
723719
reqHeaders[defHeaderName] = defHeaders[defHeaderName];
724720
}
725721

722+
// execute if header value is a function for merged headers
723+
execHeaders(reqHeaders);
726724
return reqHeaders;
727725

728726
function execHeaders(headers) {

test/ng/httpSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,18 @@ describe('$http', function() {
652652
$httpBackend.flush();
653653
});
654654

655+
it('should delete default headers if custom header function returns null', function () {
656+
657+
$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
658+
return !('Accept' in headers);
659+
}).respond('');
660+
661+
$http({url: '/url', method: 'POST', data: 'messageBody', headers: {
662+
'Accept': function() { return null; }
663+
}});
664+
$httpBackend.flush();
665+
});
666+
655667
it('should override default headers with custom in a case insensitive manner', function() {
656668
$httpBackend.expect('POST', '/url', 'messageBody', function(headers) {
657669
return headers['accept'] == 'Rewritten' &&

0 commit comments

Comments
 (0)