Repository: angular/angular
File: packages/common/http/src/transfer_cache.ts (TypeScript)

Code before:
      // and `has` calls.
      headers = appendMissingHeadersDetection(req.url, headers, headersToInclude ?? []);
    }

    return new HttpResponse({
      body,
      headers,
      status,
      statusText,
      url,
    });
  }

  return null;
}

export function transferCacheInterceptorFn(
  req: HttpRequest<unknown>,
  next: HttpHandlerFn,
): Observable<HttpEvent<unknown>> {
  const options = inject(CACHE_OPTIONS);
  const transferState = inject(TransferState);

  const originMap: Record<string, string> | null = inject(HTTP_TRANSFER_CACHE_ORIGIN_MAP, {
    optional: true,
  });

  const cachedResponse = StateFromCache(req, options, transferState, originMap);
  if (cachedResponse) {
    return of(cachedResponse);
  }

  const {isCacheActive, ...globalOptions} = options;
  const {transferCache: requestOptions, method: requestMethod} = req;
  let headersToInclude = globalOptions.includeHeaders;
  if (typeof requestOptions === 'object' && requestOptions.includeHeaders) {
    headersToInclude = requestOptions.includeHeaders;
  }

  const requestUrl =
    typeof ngServerMode !== 'undefined' && ngServerMode && originMap
      ? mapRequestOriginUrl(req.url, originMap)
      : req.url;
  const storeKey = makeCacheKey(req, requestUrl);

  // In the following situations we do not want to cache the request
  if (
    !isCacheActive ||
    requestOptions === false ||
    // POST requests are allowed either globally or at request level
    (requestMethod === 'POST' && !globalOptions.includePostRequests && !requestOptions) ||

Review comment (performance):
nit: we've moved this code without changes, but an explicit type annotation is not required here, we can simplify the code a bit:
```suggestion
  const originMap = inject(HTTP_TRANSFER_CACHE_ORIGIN_MAP, { optional: true });
```

Code after:
    // Request found in cache. Respond using it.
    let body: ArrayBuffer | Blob | string | undefined = undecodedBody;

    switch (responseType) {
      case 'arraybuffer':
        body = fromBase64(undecodedBody);
        break;
      case 'blob':
        body = new Blob([fromBase64(undecodedBody)]);
        break;
    }

    // We want to warn users accessing a header provided from the cache
    // That HttpTransferCache alters the headers
    // The warning will be logged a single time by HttpHeaders instance
    let headers = new HttpHeaders(httpHeaders);
    if (typeof ngDevMode === 'undefined' || ngDevMode) {
      // Append extra logic in dev mode to produce a warning when a header
      // that was not transferred to the client is accessed in the code via `get`
      // and `has` calls.
      headers = appendMissingHeadersDetection(req.url, headers, headersToInclude ?? []);
    }

    return new HttpResponse({
      body,
      headers,
      status,
      statusText,
      url,
    });
  }

  return null;
}

export function transferCacheInterceptorFn(
  req: HttpRequest<unknown>,
  next: HttpHandlerFn,
): Observable<HttpEvent<unknown>> {
  const options = inject(CACHE_OPTIONS);
  const transferState = inject(TransferState);

  const originMap = inject(HTTP_TRANSFER_CACHE_ORIGIN_MAP, {optional: true});

  const cachedResponse = retrieveStateFromCache(req, options, transferState, originMap);
  if (cachedResponse) {
    return of(cachedResponse);
  }

  const {transferCache: requestOptions} = req;
  const headersToInclude = getHeadersToInclude(options, requestOptions);