Skip to content

Commit

Permalink
fix redirect caching in HttpUriPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Feb 14, 2022
1 parent a6099c4 commit c128f4f
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions lib/schemes/HttpUriPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -543,15 +543,6 @@ class HttpUriPlugin {
logger.debug(
`GET ${url} [${res.statusCode}] -> ${partialResult.location}`
);
// we should follow redirect and not store partial result
return callback(null, {
...partialResult,
storeLock,
storeCache,
fresh: true,
etag: undefined,
validUntil: undefined
});
} else {
logger.debug(
`GET ${url} [${res.statusCode}] ${Math.ceil(
Expand Down Expand Up @@ -612,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 = [];
Expand Down

0 comments on commit c128f4f

Please sign in to comment.