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

Commit d162f15

Browse files
refactor($http): avoid re-creating execHeaders function
The execHeaders function was being re-defined inside mergeHeaders function. Additionally it was mutating its arguments. Closes #10359
1 parent 4025883 commit d162f15

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/ng/http.js

+18-17
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,23 @@ function $HttpProvider() {
822822
: $q.reject(resp);
823823
}
824824

825+
function executeHeaderFns(headers) {
826+
var headerContent, processedHeaders = {};
827+
828+
forEach(headers, function(headerFn, header) {
829+
if (isFunction(headerFn)) {
830+
headerContent = headerFn();
831+
if (headerContent != null) {
832+
processedHeaders[header] = headerContent;
833+
}
834+
} else {
835+
processedHeaders[header] = headerFn;
836+
}
837+
});
838+
839+
return processedHeaders;
840+
}
841+
825842
function mergeHeaders(config) {
826843
var defHeaders = defaults.headers,
827844
reqHeaders = extend({}, config.headers),
@@ -844,23 +861,7 @@ function $HttpProvider() {
844861
}
845862

846863
// execute if header value is a function for merged headers
847-
execHeaders(reqHeaders);
848-
return reqHeaders;
849-
850-
function execHeaders(headers) {
851-
var headerContent;
852-
853-
forEach(headers, function(headerFn, header) {
854-
if (isFunction(headerFn)) {
855-
headerContent = headerFn();
856-
if (headerContent != null) {
857-
headers[header] = headerContent;
858-
} else {
859-
delete headers[header];
860-
}
861-
}
862-
});
863-
}
864+
return executeHeaderFns(reqHeaders);
864865
}
865866
}
866867

0 commit comments

Comments
 (0)