(req: HttpRequest<unknown>, options: CacheOptions)
| 126 | const ALLOWED_METHODS = ['GET', 'HEAD']; |
| 127 | |
| 128 | function canUseOrCacheRequest(req: HttpRequest<unknown>, options: CacheOptions): boolean { |
| 129 | const {isCacheActive, ...globalOptions} = options; |
| 130 | const {transferCache: requestOptions, method: requestMethod} = req; |
| 131 | |
| 132 | if ( |
| 133 | !isCacheActive || |
| 134 | requestOptions === false || |
| 135 | // Do not cache requests sent with credentials. |
| 136 | hasOutgoingCredentials(req) || |
| 137 | // POST requests are allowed either globally or at request level |
| 138 | (requestMethod === 'POST' && !globalOptions.includePostRequests && !requestOptions) || |
| 139 | (requestMethod !== 'POST' && !ALLOWED_METHODS.includes(requestMethod)) || |
| 140 | // Do not cache requests with authentication or cookie headers unless explicitly enabled. |
| 141 | (!globalOptions.includeRequestsWithAuthHeaders && hasAuthHeaders(req)) || |
| 142 | // Do not cache requests that explicitly forbid caching via Cache-Control |
| 143 | // or Fetch API cache mode. |
| 144 | hasUncacheableCacheControl(req.headers) || |
| 145 | isNonCacheableRequest(req.cache) || |
| 146 | globalOptions.filter?.(req) === false |
| 147 | ) { |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | function getHeadersToInclude( |
| 155 | options: CacheOptions, |
no test coverage detected
searching dependent graphs…