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

Function canUseOrCacheRequest

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

Source from the content-addressed store, hash-verified

145const ALLOWED_METHODS = ['GET', 'HEAD'];
146
147function 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
180function getHeadersToInclude(
181 options: CacheOptions,

Callers 2

retrieveStateFromCacheFunction · 0.85

Calls 4

hasAuthHeadersFunction · 0.85
hasOutgoingCredentialsFunction · 0.85
isNonCacheableRequestFunction · 0.85

Tested by

no test coverage detected