@@ -509,7 +509,7 @@ class HttpUriPlugin {
509
509
510
510
/**
511
511
* @param {string } url URL
512
- * @param {FetchResult } cachedResult result from cache
512
+ * @param {FetchResult | RedirectFetchResult } cachedResult result from cache
513
513
* @param {function((Error | null)=, FetchResult=): void } callback callback
514
514
* @returns {void }
515
515
*/
@@ -543,15 +543,6 @@ class HttpUriPlugin {
543
543
logger . debug (
544
544
`GET ${ url } [${ res . statusCode } ] -> ${ partialResult . location } `
545
545
) ;
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
- } ) ;
555
546
} else {
556
547
logger . debug (
557
548
`GET ${ url } [${ res . statusCode } ] ${ Math . ceil (
@@ -612,9 +603,30 @@ class HttpUriPlugin {
612
603
res . statusCode >= 301 &&
613
604
res . statusCode <= 308
614
605
) {
615
- return finishWith ( {
606
+ const result = {
616
607
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
+ }
618
630
}
619
631
const contentType = res . headers [ "content-type" ] || "" ;
620
632
const bufferArr = [ ] ;
0 commit comments