Merge pull request #15370 from webpack/fix/partial-15366

fix cache invalidation in HttpUriPlugin
This commit is contained in:
Tobias Koppers 2022-02-14 14:44:31 +01:00 committed by GitHub
commit 4edf949da3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View File

@ -509,7 +509,7 @@ class HttpUriPlugin {
/**
* @param {string} url URL
* @param {FetchResult} cachedResult result from cache
* @param {FetchResult | RedirectFetchResult} cachedResult result from cache
* @param {function((Error | null)=, FetchResult=): void} callback callback
* @returns {void}
*/
@ -603,9 +603,30 @@ class HttpUriPlugin {
res.statusCode >= 301 &&
res.statusCode <= 308
) {
return finishWith({
const result = {
location: new URL(location, url).href
});
};
if (
!cachedResult ||
!("location" in cachedResult) ||
cachedResult.location !== result.location ||
cachedResult.validUntil < validUntil ||
cachedResult.storeLock !== storeLock ||
cachedResult.storeCache !== storeCache ||
cachedResult.etag !== etag
) {
return finishWith(result);
} else {
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
return callback(null, {
...result,
fresh: true,
storeLock,
storeCache,
validUntil,
etag
});
}
}
const contentType = res.headers["content-type"] || "";
const bufferArr = [];

View File

@ -19,10 +19,6 @@ describeCases({
/^Pack got invalid because of write to: Compilation\/modules.+loaders[/\\]options[/\\]error1\.js$/,
/^Pack got invalid because of write to: Compilation\/modules.+loaders[/\\]options[/\\]error2\.js$/
]
},
["asset-modules"]: {
["http-url"]:
/^Pack got invalid because of write to: webpack\.HttpUriPlugin|https:\/\/raw.githubusercontent.com\/\/webpack\/\/webpack\/\/main\/CODE_OF_CONDUCT\.md$/
}
},
cache: {