(url, cachedResult, callback)
| 813 | * @returns {void} |
| 814 | */ |
| 815 | const fetchContentRaw = (url, cachedResult, callback) => { |
| 816 | const requestTime = Date.now(); |
| 817 | /** @type {OutgoingHttpHeaders} */ |
| 818 | const headers = { |
| 819 | "accept-encoding": "gzip, deflate, br", |
| 820 | "user-agent": "webpack" |
| 821 | }; |
| 822 | |
| 823 | if (cachedResult && cachedResult.etag) { |
| 824 | headers["if-none-match"] = cachedResult.etag; |
| 825 | } |
| 826 | |
| 827 | fetch(new URL(url), { headers }, (res) => { |
| 828 | const etag = res.headers.etag; |
| 829 | const location = res.headers.location; |
| 830 | const cacheControl = res.headers["cache-control"]; |
| 831 | const { storeLock, storeCache, validUntil } = parseCacheControl( |
| 832 | cacheControl, |
| 833 | requestTime |
| 834 | ); |
| 835 | /** |
| 836 | * Processes the provided partial result. |
| 837 | * @param {Partial<Pick<FetchResultMeta, "fresh">> & (Pick<RedirectFetchResult, "location"> | Pick<ContentFetchResult, "content" | "entry">)} partialResult result |
| 838 | * @returns {void} |
| 839 | */ |
| 840 | const finishWith = (partialResult) => { |
| 841 | if ("location" in partialResult) { |
| 842 | logger.debug( |
| 843 | `GET ${url} [${res.statusCode}] -> ${partialResult.location}` |
| 844 | ); |
| 845 | } else { |
| 846 | logger.debug( |
| 847 | `GET ${url} [${res.statusCode}] ${Math.ceil( |
| 848 | partialResult.content.length / 1024 |
| 849 | )} kB${!storeLock ? " no-cache" : ""}` |
| 850 | ); |
| 851 | } |
| 852 | const result = { |
| 853 | ...partialResult, |
| 854 | fresh: true, |
| 855 | storeLock, |
| 856 | storeCache, |
| 857 | validUntil, |
| 858 | etag |
| 859 | }; |
| 860 | if (!storeCache) { |
| 861 | logger.log( |
| 862 | `${url} can't be stored in cache, due to Cache-Control header: ${cacheControl}` |
| 863 | ); |
| 864 | return callback(null, result); |
| 865 | } |
| 866 | cache.store( |
| 867 | url, |
| 868 | null, |
| 869 | { |
| 870 | ...result, |
| 871 | fresh: false |
| 872 | }, |
nothing calls this directly
no test coverage detected