(req: HttpRequest<unknown>, options: CacheOptions)
| 147 | const ALLOWED_METHODS = ['GET', 'HEAD', 'QUERY']; |
| 148 | |
| 149 | function canUseOrCacheRequest(req: HttpRequest<unknown>, options: CacheOptions): boolean { |
| 150 | const { |
| 151 | isCacheActive, |
| 152 | filter, |
| 153 | includePostRequests, |
| 154 | includeRequestsWithAuthHeaders, |
| 155 | includeRequestsWithCredentials, |
| 156 | includeNonCacheableRequests, |
| 157 | } = options; |
| 158 | const {transferCache: requestOptions, method: requestMethod} = req; |
| 159 | |
| 160 | if ( |
| 161 | !isCacheActive || |
| 162 | requestOptions === false || |
| 163 | // POST requests are allowed either globally or at request level |
| 164 | (requestMethod === 'POST' && !includePostRequests && !requestOptions) || |
| 165 | (requestMethod !== 'POST' && !ALLOWED_METHODS.includes(requestMethod)) || |
| 166 | // Do not cache requests with authentication or cookie headers unless explicitly enabled. |
| 167 | (!includeRequestsWithAuthHeaders && hasAuthHeaders(req)) || |
| 168 | // Do not cache requests sent with credentials unless explicitly enabled. |
| 169 | (!includeRequestsWithCredentials && hasOutgoingCredentials(req)) || |
| 170 | // Do not cache requests that explicitly forbid caching via Cache-Control |
| 171 | // or Fetch API cache mode unless explicitly enabled. |
| 172 | (!includeNonCacheableRequests && |
| 173 | (hasUncacheableCacheControl(req.headers) || isNonCacheableRequest(req.cache))) || |
| 174 | filter?.(req) === false |
| 175 | ) { |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | return true; |
| 180 | } |
| 181 | |
| 182 | function getHeadersToInclude( |
| 183 | options: CacheOptions, |
no test coverage detected