This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +20
-6
lines changed
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -56,9 +56,9 @@ function parseHeaders(headers) {
56
56
57
57
58
58
/**
59
- * Returns a function that provides access to parsed headers.
59
+ * Returns a function that provides access to headers.
60
60
*
61
- * Headers are lazy parsed when first requested.
61
+ * Headers provided as string are lazy parsed when first requested.
62
62
* @see parseHeaders
63
63
*
64
64
* @param {(string|Object) } headers Headers to provide access to.
@@ -71,14 +71,16 @@ function headersGetter(headers) {
71
71
var headersObj = isObject ( headers ) ? headers : undefined ;
72
72
73
73
return function ( name ) {
74
+ var existingHeaderName , lowercaseName = lowercase ( name ) ;
74
75
if ( ! headersObj ) headersObj = parseHeaders ( headers ) ;
75
76
76
77
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
+ }
80
82
}
81
- return value ;
83
+ return null ;
82
84
}
83
85
84
86
return headersObj ;
Original file line number Diff line number Diff line change @@ -1038,6 +1038,18 @@ describe('$http', function() {
1038
1038
expect ( callback ) . toHaveBeenCalledOnce ( ) ;
1039
1039
} ) ;
1040
1040
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
+ } ) ;
1041
1053
1042
1054
it ( 'should pipeline more functions' , function ( ) {
1043
1055
function first ( d , h ) { return d + '-first' + ':' + h ( 'h1' ) ; }
You can’t perform that action at this time.
0 commit comments