MCPcopy Create free account
hub / github.com/angular/angular / canUseOrCacheRequest

Function canUseOrCacheRequest

packages/common/http/src/transfer_cache.ts:149–180  ·  view source on GitHub ↗
(req: HttpRequest<unknown>, options: CacheOptions)

Source from the content-addressed store, hash-verified

147const ALLOWED_METHODS = ['GET', 'HEAD', 'QUERY'];
148
149function 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
182function getHeadersToInclude(
183 options: CacheOptions,

Callers 2

retrieveStateFromCacheFunction · 0.85

Calls 4

hasAuthHeadersFunction · 0.85
hasOutgoingCredentialsFunction · 0.85
isNonCacheableRequestFunction · 0.85

Tested by

no test coverage detected