@@ -52,15 +52,15 @@ const INCOMPLETE_RETRY_LIMIT = process.env.GATSBY_INCOMPLETE_RETRY_LIMIT
52
52
* @param {String } url
53
53
* @param {Headers } headers
54
54
* @param {String } tmpFilename
55
- * @param {Object } httpOpts
55
+ * @param {Object } httpOptions
56
56
* @param {number } attempt
57
57
* @return {Promise<Object> } Resolves with the [http Result Object]{@link https://nodejs.org/api/http.html#http_class_http_serverresponse}
58
58
*/
59
59
const requestRemoteNode = (
60
60
url : got . GotUrl ,
61
61
headers : OutgoingHttpHeaders ,
62
62
tmpFilename : string ,
63
- httpOpts : got . GotOptions < string | null > | undefined ,
63
+ httpOptions : got . GotOptions < string | null > | undefined ,
64
64
attempt : number = 1
65
65
) : Promise < IncomingMessage > =>
66
66
new Promise ( ( resolve , reject ) => {
@@ -74,7 +74,7 @@ const requestRemoteNode = (
74
74
if ( attempt < STALL_RETRY_LIMIT ) {
75
75
// Retry by calling ourself recursively
76
76
resolve (
77
- requestRemoteNode ( url , headers , tmpFilename , httpOpts , attempt + 1 )
77
+ requestRemoteNode ( url , headers , tmpFilename , httpOptions , attempt + 1 )
78
78
)
79
79
} else {
80
80
reject ( `Failed to download ${ url } after ${ STALL_RETRY_LIMIT } attempts` )
@@ -92,7 +92,7 @@ const requestRemoteNode = (
92
92
timeout : {
93
93
send : CONNECTION_TIMEOUT , // https://github.com/sindresorhus/got#timeout
94
94
} ,
95
- ...httpOpts ,
95
+ ...httpOptions ,
96
96
} )
97
97
98
98
let haveAllBytesBeenWritten = false
@@ -140,7 +140,7 @@ const requestRemoteNode = (
140
140
url ,
141
141
headers ,
142
142
tmpFilename ,
143
- httpOpts ,
143
+ httpOptions ,
144
144
attempt + 1
145
145
)
146
146
)
@@ -177,11 +177,15 @@ export async function fetchRemoteFile({
177
177
headers [ `If-None-Match` ] = cachedHeaders . etag
178
178
}
179
179
180
- // Add htaccess authentication if passed in. This isn't particularly
181
- // extensible. We should define a proper API that we validate.
182
- const httpOpts : got . GotOptions < string | null > = { }
180
+ // Add Basic authentication if passed in:
181
+ // https://github.com/sindresorhus/got/blob/main/documentation/2-options.md#username
182
+ // The "auth" API isn't particularly extensible, we should define an API that we validate
183
+ const httpOptions : got . GotOptions < string | null > = { }
183
184
if ( auth && ( auth . htaccess_pass || auth . htaccess_user ) ) {
184
- httpOpts . auth = `${ auth . htaccess_user } :${ auth . htaccess_pass } `
185
+ // @ts -ignore - We use outdated @types/got typings. Once we update got everywhere we can remove @types/got and have correct typings
186
+ httpOptions . username = auth . htaccess_user
187
+ // @ts -ignore - see above
188
+ httpOptions . password = auth . htaccess_pass
185
189
}
186
190
187
191
// Create the temp and permanent file names for the url.
@@ -196,7 +200,12 @@ export async function fetchRemoteFile({
196
200
const tmpFilename = createFilePath ( pluginCacheDir , `tmp-${ digest } ` , ext )
197
201
198
202
// Fetch the file.
199
- const response = await requestRemoteNode ( url , headers , tmpFilename , httpOpts )
203
+ const response = await requestRemoteNode (
204
+ url ,
205
+ headers ,
206
+ tmpFilename ,
207
+ httpOptions
208
+ )
200
209
201
210
if ( response . statusCode === 200 ) {
202
211
// Save the response headers for future requests.
0 commit comments