Skip to content
Permalink
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
  • Loading branch information
pkozlowski-opensource committed Dec 7, 2014
1 parent 4025883 commit d162f152b881068163e144a66fd5b9b7c916911d
Showing with 18 additions and 17 deletions.
  1. +18 −17 src/ng/http.js
@@ -822,6 +822,23 @@ function $HttpProvider() {
: $q.reject(resp);
}

function executeHeaderFns(headers) {
var headerContent, processedHeaders = {};

forEach(headers, function(headerFn, header) {
if (isFunction(headerFn)) {
headerContent = headerFn();
if (headerContent != null) {
processedHeaders[header] = headerContent;
}
} else {
processedHeaders[header] = headerFn;
}
});

return processedHeaders;
}

function mergeHeaders(config) {
var defHeaders = defaults.headers,
reqHeaders = extend({}, config.headers),
@@ -844,23 +861,7 @@ function $HttpProvider() {
}

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

function execHeaders(headers) {
var headerContent;

forEach(headers, function(headerFn, header) {
if (isFunction(headerFn)) {
headerContent = headerFn();
if (headerContent != null) {
headers[header] = headerContent;
} else {
delete headers[header];
}
}
});
}
return executeHeaderFns(reqHeaders);
}
}

0 comments on commit d162f15

Please sign in to comment.
You can’t perform that action at this time.