11import { AxiosResponseHeaders , RawAxiosResponseHeaders } from "axios" ;
2+ import {
3+ isBooleanRecord ,
4+ isEmpty ,
5+ isNumberRecord ,
6+ isStringRecord ,
7+ parseParamDecorator ,
8+ } from "./utils" ;
29
310import { ParamDecorator } from "./pathparams" ;
4- import { parseParamDecorator } from "./utils" ;
5- import { isStringRecord , isNumberRecord , isBooleanRecord , isEmpty } from "./utils" ;
611
712export const headerMetadataKey = "header" ;
813
@@ -35,9 +40,30 @@ export function getHeadersFromRequest(headerParams: any): any {
3540
3641export function getHeadersFromResponse (
3742 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 ;
4167}
4268
4369function serializeHeader ( header : any , explode : boolean ) : string {
@@ -46,7 +72,11 @@ function serializeHeader(header: any, explode: boolean): string {
4672 header . forEach ( ( val : any ) => {
4773 headerVals . push ( String ( val ) ) ;
4874 } ) ;
49- } else if ( isStringRecord ( header ) || isNumberRecord ( header ) || isBooleanRecord ( header ) ) {
75+ } else if (
76+ isStringRecord ( header ) ||
77+ isNumberRecord ( header ) ||
78+ isBooleanRecord ( header )
79+ ) {
5080 Object . getOwnPropertyNames ( header ) . forEach ( ( headerKey : string ) => {
5181 if ( explode ) headerVals . push ( `${ headerKey } =${ header [ headerKey ] } ` ) ;
5282 else headerVals . push ( `${ headerKey } ,${ header [ headerKey ] } ` ) ;
0 commit comments