Skip to content

Commit c128f4f

Browse files
committed
fix redirect caching in HttpUriPlugin
1 parent a6099c4 commit c128f4f

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

lib/schemes/HttpUriPlugin.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ class HttpUriPlugin {
509509

510510
/**
511511
* @param {string} url URL
512-
* @param {FetchResult} cachedResult result from cache
512+
* @param {FetchResult | RedirectFetchResult} cachedResult result from cache
513513
* @param {function((Error | null)=, FetchResult=): void} callback callback
514514
* @returns {void}
515515
*/
@@ -543,15 +543,6 @@ class HttpUriPlugin {
543543
logger.debug(
544544
`GET ${url} [${res.statusCode}] -> ${partialResult.location}`
545545
);
546-
// we should follow redirect and not store partial result
547-
return callback(null, {
548-
...partialResult,
549-
storeLock,
550-
storeCache,
551-
fresh: true,
552-
etag: undefined,
553-
validUntil: undefined
554-
});
555546
} else {
556547
logger.debug(
557548
`GET ${url} [${res.statusCode}] ${Math.ceil(
@@ -612,9 +603,30 @@ class HttpUriPlugin {
612603
res.statusCode >= 301 &&
613604
res.statusCode <= 308
614605
) {
615-
return finishWith({
606+
const result = {
616607
location: new URL(location, url).href
617-
});
608+
};
609+
if (
610+
!cachedResult ||
611+
!("location" in cachedResult) ||
612+
cachedResult.location !== result.location ||
613+
cachedResult.validUntil < validUntil ||
614+
cachedResult.storeLock !== storeLock ||
615+
cachedResult.storeCache !== storeCache ||
616+
cachedResult.etag !== etag
617+
) {
618+
return finishWith(result);
619+
} else {
620+
logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
621+
return callback(null, {
622+
...result,
623+
fresh: true,
624+
storeLock,
625+
storeCache,
626+
validUntil,
627+
etag
628+
});
629+
}
618630
}
619631
const contentType = res.headers["content-type"] || "";
620632
const bufferArr = [];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy