File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
packages/openai-adapters/src Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,35 @@ export function customFetch(
158158 if ( process . env . FEATURE_FLAG_DISABLE_CUSTOM_FETCH ) {
159159 return patchedFetch ;
160160 }
161+
162+ function letRequestOptionsOverrideAuthorizationHeader ( init : any ) : any {
163+ if (
164+ ! init ||
165+ ! init . headers ||
166+ ! requestOptions ||
167+ ! requestOptions . headers ||
168+ ( ! requestOptions . headers [ "Authorization" ] &&
169+ ! requestOptions . headers [ "authorization" ] )
170+ ) {
171+ return init ;
172+ }
173+
174+ if ( init . headers instanceof Headers ) {
175+ init . headers . delete ( "Authorization" ) ;
176+ } else if ( Array . isArray ( init . headers ) ) {
177+ init . headers = init . headers . filter (
178+ ( header : [ string , string ] ) =>
179+ ( header [ 0 ] ?? "" ) . toLowerCase ( ) !== "authorization" ,
180+ ) ;
181+ } else if ( typeof init . headers === "object" ) {
182+ delete init . headers [ "Authorization" ] ;
183+ delete init . headers [ "authorization" ] ;
184+ }
185+ return init ;
186+ }
187+
161188 return ( req : URL | string | Request , init ?: any ) => {
189+ init = letRequestOptionsOverrideAuthorizationHeader ( init ) ;
162190 if ( typeof req === "string" || req instanceof URL ) {
163191 return fetchwithRequestOptions ( req , init , requestOptions ) ;
164192 } else {
You can’t perform that action at this time.
0 commit comments