@@ -11,7 +11,7 @@ import { HttpProxyAgent } from 'http-proxy-agent'
1111
1212import findEdgePath from './finder.js'
1313import { TAGGED_VERSIONS , EDGE_PRODUCTS_API , EDGEDRIVER_BUCKET , TAGGED_VERSION_URL , LATEST_RELEASE_URL , DOWNLOAD_URL , BINARY_FILE , log } from './constants.js'
14- import { hasAccess , getNameByArchitecture , sleep } from './utils.js'
14+ import { hasAccess , getNameByArchitecture , sleep , extractBasicAuthFromUrl } from './utils.js'
1515
1616interface ProductAPIResponse {
1717 Product : string
@@ -67,9 +67,14 @@ export async function download (
6767
6868async function downloadDriver ( version : string ) {
6969 try {
70- const downloadUrl = format ( DOWNLOAD_URL , version , getNameByArchitecture ( ) )
70+ const rawDownloadUrl = format ( DOWNLOAD_URL , version , getNameByArchitecture ( ) )
71+ const { url : downloadUrl , authHeader } = extractBasicAuthFromUrl ( rawDownloadUrl )
7172 log . info ( `Downloading Edgedriver from ${ downloadUrl } ` )
72- const res = await fetch ( downloadUrl , fetchOpts )
73+ const opts : NodeRequestInit = { ...fetchOpts }
74+ if ( authHeader ) {
75+ opts . headers = { ...opts . headers , Authorization : authHeader }
76+ }
77+ const res = await fetch ( downloadUrl , opts )
7378
7479 if ( ! res . body || ! res . ok || res . status !== 200 ) {
7580 throw new Error ( `Failed to download binary from ${ downloadUrl } (statusCode ${ res . status } )` )
@@ -112,9 +117,14 @@ async function downloadDriver(version: string) {
112117 log . info ( `Downloading alternative Edgedriver version from ${ alternativeDownloadUrl } ` )
113118 const versionResponse = await fetch ( alternativeDownloadUrl , fetchOpts )
114119 const alternativeVersion = sanitizeVersion ( await versionResponse . text ( ) )
115- const downloadUrl = format ( DOWNLOAD_URL , alternativeVersion , getNameByArchitecture ( ) )
120+ const rawDownloadUrl = format ( DOWNLOAD_URL , alternativeVersion , getNameByArchitecture ( ) )
121+ const { url : downloadUrl , authHeader } = extractBasicAuthFromUrl ( rawDownloadUrl )
116122 log . info ( `Downloading Edgedriver from ${ downloadUrl } ` )
117- const res = await fetch ( downloadUrl , fetchOpts )
123+ const opts : NodeRequestInit = { ...fetchOpts }
124+ if ( authHeader ) {
125+ opts . headers = { ...opts . headers , Authorization : authHeader }
126+ }
127+ const res = await fetch ( downloadUrl , opts )
118128 if ( ! res . body || ! res . ok || res . status !== 200 ) {
119129 throw new Error ( `Failed to download binary from ${ downloadUrl } (statusCode ${ res . status } )` )
120130 }
0 commit comments