mirror of https://github.com/webpack/webpack.git
				
				
				
			fix redirect caching in HttpUriPlugin
This commit is contained in:
		
							parent
							
								
									a6099c4ff9
								
							
						
					
					
						commit
						c128f4fe44
					
				|  | @ -509,7 +509,7 @@ class HttpUriPlugin { | ||||||
| 
 | 
 | ||||||
| 					/** | 					/** | ||||||
| 					 * @param {string} url URL | 					 * @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 | 					 * @param {function((Error | null)=, FetchResult=): void} callback callback | ||||||
| 					 * @returns {void} | 					 * @returns {void} | ||||||
| 					 */ | 					 */ | ||||||
|  | @ -543,15 +543,6 @@ class HttpUriPlugin { | ||||||
| 										logger.debug( | 										logger.debug( | ||||||
| 											`GET ${url} [${res.statusCode}] -> ${partialResult.location}` | 											`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 { | 									} else { | ||||||
| 										logger.debug( | 										logger.debug( | ||||||
| 											`GET ${url} [${res.statusCode}] ${Math.ceil( | 											`GET ${url} [${res.statusCode}] ${Math.ceil( | ||||||
|  | @ -612,9 +603,30 @@ class HttpUriPlugin { | ||||||
| 									res.statusCode >= 301 && | 									res.statusCode >= 301 && | ||||||
| 									res.statusCode <= 308 | 									res.statusCode <= 308 | ||||||
| 								) { | 								) { | ||||||
| 									return finishWith({ | 									const result = { | ||||||
| 										location: new URL(location, url).href | 										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 contentType = res.headers["content-type"] || ""; | ||||||
| 								const bufferArr = []; | 								const bufferArr = []; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue