@@ -86,54 +86,36 @@ export const fetchToAxiosConfig = (
8686 return axiosConfig ;
8787} ;
8888
89- export function axiosToFetchResponse (
90- axiosRes : AxiosResponse ,
91- sanitizeHeadersFn ?: ( headers : Record < string , string > ) => Record < string , string >
92- ) : Response {
89+ export function axiosToFetchResponse ( axiosRes : AxiosResponse ) : Response {
9390 const { data, status, statusText, headers : rawHeaders } = axiosRes ;
94-
91+
9592 let body : BodyInit ;
96- let contentType = 'application/json' ;
97-
98- if ( data instanceof Blob || typeof data === 'string' || data instanceof ArrayBuffer ) {
99- body = data ;
100- contentType = rawHeaders [ 'content-type' ] || 'application/octet-stream' ;
93+ let contentType = "application/json" ;
94+
95+ if (
96+ data instanceof Blob ||
97+ typeof data === "string" ||
98+ data instanceof ArrayBuffer
99+ ) {
100+ body = data ;
101+ contentType = rawHeaders [ "content-type" ] || "application/octet-stream" ;
101102 } else {
102- body = JSON . stringify ( data ) ;
103+ body = JSON . stringify ( data ) ;
103104 }
104-
105- const headersObj = sanitizeHeadersFn
106- ? sanitizeHeadersFn (
107- Object . fromEntries (
108- Object . entries ( rawHeaders ) . map ( ( [ key , value ] ) => [ key , String ( value ) ] )
109- )
110- )
111- : Object . fromEntries (
112- Object . entries ( rawHeaders ) . map ( ( [ key , value ] ) => [ key , String ( value ) ] )
113- ) ;
114-
115- if ( ! headersObj [ 'content-type' ] ) {
116- headersObj [ 'content-type' ] = contentType ;
105+
106+ const headersObj = Object . fromEntries (
107+ Object . entries ( rawHeaders ) . map ( ( [ key , value ] ) => [ key , String ( value ) ] )
108+ ) ;
109+
110+ if ( ! headersObj [ "content-type" ] ) {
111+ headersObj [ "content-type" ] = contentType ;
117112 }
118-
113+
119114 const responseInit : ResponseInit = {
120- status,
121- statusText,
122- headers : new Headers ( headersObj ) ,
115+ status,
116+ statusText,
117+ headers : new Headers ( headersObj ) ,
123118 } ;
124-
119+
125120 return new Response ( body , responseInit ) ;
126- }
127-
128- export function sanitizeFetchResponseHeader ( headers : Record < string , string > ) : Record < string , string > {
129- const blocked = [ 'authorization' , 'cookie' , 'set-cookie' ] ;
130- const sanitized : Record < string , string > = { } ;
131-
132- for ( const [ key , value ] of Object . entries ( headers ) ) {
133- if ( ! blocked . includes ( key . toLowerCase ( ) ) ) {
134- sanitized [ key ] = value ;
135- }
136- }
137-
138- return sanitized ;
139- }
121+ }
0 commit comments