@@ -37,19 +37,24 @@ function isJsonLike(str) {
37
37
* @returns {Object } Parsed headers as key value object
38
38
*/
39
39
function parseHeaders ( headers ) {
40
- var parsed = createMap ( ) , key , val , i ;
41
-
42
- if ( ! headers ) return parsed ;
43
-
44
- forEach ( headers . split ( '\n' ) , function ( line ) {
45
- i = line . indexOf ( ':' ) ;
46
- key = lowercase ( trim ( line . substr ( 0 , i ) ) ) ;
47
- val = trim ( line . substr ( i + 1 ) ) ;
40
+ var parsed = createMap ( ) , i ;
48
41
42
+ function fillInParsed ( key , val ) {
49
43
if ( key ) {
50
44
parsed [ key ] = parsed [ key ] ? parsed [ key ] + ', ' + val : val ;
51
45
}
52
- } ) ;
46
+ }
47
+
48
+ if ( isString ( headers ) ) {
49
+ forEach ( headers . split ( '\n' ) , function ( line ) {
50
+ i = line . indexOf ( ':' ) ;
51
+ fillInParsed ( lowercase ( trim ( line . substr ( 0 , i ) ) ) , trim ( line . substr ( i + 1 ) ) ) ;
52
+ } ) ;
53
+ } else if ( isObject ( headers ) ) {
54
+ forEach ( headers , function ( headerVal , headerKey ) {
55
+ fillInParsed ( lowercase ( headerKey ) , trim ( headerVal ) ) ;
56
+ } ) ;
57
+ }
53
58
54
59
return parsed ;
55
60
}
@@ -68,7 +73,7 @@ function parseHeaders(headers) {
68
73
* - if called with no arguments returns an object containing all headers.
69
74
*/
70
75
function headersGetter ( headers ) {
71
- var headersObj = isObject ( headers ) ? headers : undefined ;
76
+ var headersObj ;
72
77
73
78
return function ( name ) {
74
79
if ( ! headersObj ) headersObj = parseHeaders ( headers ) ;
0 commit comments