File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,20 @@ async function downloadFile(params: {
5555 const { url, maxBytes, timeoutInSeconds } = params
5656 const abortController = new AbortController ( )
5757 const timeoutSignal = AbortSignal . timeout ( timeoutInSeconds * 1000 )
58- const response = await fetch ( url , {
58+ let headers : { [ key : string ] : string } = { }
59+ // Extract basic auth from URL and construct an Authorization header instead.
60+ if ( ( url . username && url . username . length > 0 ) || ( url . password && url . password . length > 0 ) ) {
61+ const username = decodeURIComponent ( url . username )
62+ const password = decodeURIComponent ( url . password )
63+ headers [ "Authorization" ] = "Basic " + btoa ( `${ username } :${ password } ` )
64+ }
65+ // Make sure basic auth is removed from URL.
66+ const urlWithoutAuth = url
67+ urlWithoutAuth . username = ""
68+ urlWithoutAuth . password = ""
69+ const response = await fetch ( urlWithoutAuth , {
70+ method : "GET" ,
71+ headers,
5972 signal : AbortSignal . any ( [ abortController . signal , timeoutSignal ] )
6073 } )
6174 if ( ! response . body ) {
You can’t perform that action at this time.
0 commit comments