@@ -14,7 +14,8 @@ const {
14
14
getRemoteFileName,
15
15
createFilePath,
16
16
} = require ( `./utils` )
17
- const cacheId = url => `create-remote-file-node-${ url } `
17
+ const cacheIdForHeaders = url => `create-remote-file-node-headers-${ url } `
18
+ const cacheIdForExtensions = url => `create-remote-file-node-extension-${ url } `
18
19
19
20
let bar
20
21
// Keep track of the total number of jobs we push in the queue
@@ -208,7 +209,7 @@ async function processRemoteNode({
208
209
const pluginCacheDir = cache . directory
209
210
// See if there's response headers for this url
210
211
// from a previous request.
211
- const cachedHeaders = await cache . get ( cacheId ( url ) )
212
+ const cachedHeaders = await cache . get ( cacheIdForHeaders ( url ) )
212
213
213
214
const headers = { ...httpHeaders }
214
215
if ( cachedHeaders && cachedHeaders . etag ) {
@@ -238,15 +239,22 @@ async function processRemoteNode({
238
239
239
240
if ( response . statusCode == 200 ) {
240
241
// Save the response headers for future requests.
241
- await cache . set ( cacheId ( url ) , response . headers )
242
+ await cache . set ( cacheIdForHeaders ( url ) , response . headers )
242
243
}
243
244
244
245
// If the user did not provide an extension and we couldn't get one from remote file, try and guess one
245
246
if ( ext === `` ) {
246
- const buffer = readChunk . sync ( tmpFilename , 0 , fileType . minimumBytes )
247
- const filetype = fileType ( buffer )
248
- if ( filetype ) {
249
- ext = `.${ filetype . ext } `
247
+ if ( response . statusCode === 200 ) {
248
+ // if this is fresh response - try to guess extension and cache result for future
249
+ const buffer = readChunk . sync ( tmpFilename , 0 , fileType . minimumBytes )
250
+ const filetype = fileType ( buffer )
251
+ if ( filetype ) {
252
+ ext = `.${ filetype . ext } `
253
+ await cache . set ( cacheIdForExtensions ( url ) , ext )
254
+ }
255
+ } else if ( response . statusCode === 304 ) {
256
+ // if file on server didn't change - grab cached extension
257
+ ext = await cache . get ( cacheIdForExtensions ( url ) )
250
258
}
251
259
}
252
260
0 commit comments