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