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

Commit b7b3300

Browse files
fix($http): properly access request headers with mixed case
Fixes #10881
1 parent 560951e commit b7b3300

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/ng/http.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ function parseHeaders(headers) {
5656

5757

5858
/**
59-
* Returns a function that provides access to parsed headers.
59+
* Returns a function that provides access to headers.
6060
*
61-
* Headers are lazy parsed when first requested.
61+
* Headers provided as string are lazy parsed when first requested.
6262
* @see parseHeaders
6363
*
6464
* @param {(string|Object)} headers Headers to provide access to.
@@ -71,14 +71,16 @@ function headersGetter(headers) {
7171
var headersObj = isObject(headers) ? headers : undefined;
7272

7373
return function(name) {
74+
var existingHeaderName, lowercaseName = lowercase(name);
7475
if (!headersObj) headersObj = parseHeaders(headers);
7576

7677
if (name) {
77-
var value = headersObj[lowercase(name)];
78-
if (value === void 0) {
79-
value = null;
78+
for (existingHeaderName in headersObj) {
79+
if (lowercase(existingHeaderName) === lowercaseName) {
80+
return isDefined(headersObj[existingHeaderName]) ? headersObj[existingHeaderName] : null;
81+
}
8082
}
81-
return value;
83+
return null;
8284
}
8385

8486
return headersObj;

test/ng/httpSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,18 @@ describe('$http', function() {
10381038
expect(callback).toHaveBeenCalledOnce();
10391039
});
10401040

1041+
it('should have access to request headers with mixed case', function() {
1042+
$httpBackend.expect('POST', '/url', 'header1').respond(200);
1043+
$http.post('/url', 'req', {
1044+
headers: {H1: 'header1'},
1045+
transformRequest: function(data, headers) {
1046+
return headers('H1');
1047+
}
1048+
}).success(callback);
1049+
$httpBackend.flush();
1050+
1051+
expect(callback).toHaveBeenCalledOnce();
1052+
});
10411053

10421054
it('should pipeline more functions', function() {
10431055
function first(d, h) {return d + '-first' + ':' + h('h1');}

0 commit comments

Comments
 (0)