1
1
import { AxiosResponseHeaders , RawAxiosResponseHeaders } from "axios" ;
2
+ import {
3
+ isBooleanRecord ,
4
+ isEmpty ,
5
+ isNumberRecord ,
6
+ isStringRecord ,
7
+ parseParamDecorator ,
8
+ } from "./utils" ;
2
9
3
10
import { ParamDecorator } from "./pathparams" ;
4
- import { parseParamDecorator } from "./utils" ;
5
- import { isStringRecord , isNumberRecord , isBooleanRecord , isEmpty } from "./utils" ;
6
11
7
12
export const headerMetadataKey = "header" ;
8
13
@@ -35,9 +40,30 @@ export function getHeadersFromRequest(headerParams: any): any {
35
40
36
41
export function getHeadersFromResponse (
37
42
headers : RawAxiosResponseHeaders | AxiosResponseHeaders
38
- ) : Map < string , string [ ] > {
39
- // TODO: convert Axios response headers to map
40
- return new Map < string , string [ ] > ( ) ;
43
+ ) : Record < string , string [ ] > {
44
+ const reponseHeaders : Record < string , string [ ] > = { } ;
45
+
46
+ Object . keys ( headers ) . forEach ( ( key ) => {
47
+ const value = headers [ key ] ;
48
+
49
+ if ( ! value ) return ;
50
+
51
+ if ( Array . isArray ( value ) ) {
52
+ const h : string [ ] = [ ] ;
53
+
54
+ value . forEach ( ( val : any ) => {
55
+ if ( val ) {
56
+ h . push ( String ( val ) ) ;
57
+ }
58
+ } ) ;
59
+
60
+ reponseHeaders [ key ] = h ;
61
+ } else {
62
+ reponseHeaders [ key ] = [ value ] ;
63
+ }
64
+ } ) ;
65
+
66
+ return reponseHeaders ;
41
67
}
42
68
43
69
function serializeHeader ( header : any , explode : boolean ) : string {
@@ -46,7 +72,11 @@ function serializeHeader(header: any, explode: boolean): string {
46
72
header . forEach ( ( val : any ) => {
47
73
headerVals . push ( String ( val ) ) ;
48
74
} ) ;
49
- } else if ( isStringRecord ( header ) || isNumberRecord ( header ) || isBooleanRecord ( header ) ) {
75
+ } else if (
76
+ isStringRecord ( header ) ||
77
+ isNumberRecord ( header ) ||
78
+ isBooleanRecord ( header )
79
+ ) {
50
80
Object . getOwnPropertyNames ( header ) . forEach ( ( headerKey : string ) => {
51
81
if ( explode ) headerVals . push ( `${ headerKey } =${ header [ headerKey ] } ` ) ;
52
82
else headerVals . push ( `${ headerKey } ,${ header [ headerKey ] } ` ) ;
0 commit comments