MCPcopy Index your code
hub / github.com/angular/angular / appendMissingHeadersDetection

Function appendMissingHeadersDetection

packages/common/http/src/transfer_cache.ts:474–515  ·  view source on GitHub ↗

* This function will add a proxy to an HttpHeader to intercept calls to get/has * and log a warning if the header entry requested has been removed

(
  url: string,
  headers: HttpHeaders,
  headersToInclude: string[],
)

Source from the content-addressed store, hash-verified

472 * and log a warning if the header entry requested has been removed
473 */
474function appendMissingHeadersDetection(
475 url: string,
476 headers: HttpHeaders,
477 headersToInclude: string[],
478): HttpHeaders {
479 const warningProduced = new Set();
480 return new Proxy<HttpHeaders>(headers, {
481 get(target: HttpHeaders, prop: keyof HttpHeaders): unknown {
482 const value = Reflect.get(target, prop);
483 const methods: Set<keyof HttpHeaders> = new Set(['get', 'has', 'getAll']);
484
485 if (typeof value !== 'function' || !methods.has(prop)) {
486 return value;
487 }
488
489 return (headerName: string) => {
490 // We log when the key has been removed and a warning hasn't been produced for the header
491 const key = (prop + ':' + headerName).toLowerCase(); // e.g. `get:cache-control`
492 if (!headersToInclude.includes(headerName) && !warningProduced.has(key)) {
493 warningProduced.add(key);
494 const truncatedUrl = truncateMiddle(url);
495
496 console.warn(
497 formatRuntimeError(
498 RuntimeErrorCode.HEADERS_ALTERED_BY_TRANSFER_CACHE,
499 `Angular detected that the \`${headerName}\` header is accessed, but the value of the header ` +
500 `was not transferred from the server to the client by the HttpTransferCache. ` +
501 `To include the value of the \`${headerName}\` header for the \`${truncatedUrl}\` request, ` +
502 `use the \`includeHeaders\` list. The \`includeHeaders\` can be defined either ` +
503 `on a request level by adding the \`transferCache\` parameter, or on an application ` +
504 `level by adding the \`httpCacheTransfer.includeHeaders\` argument to the ` +
505 `\`provideClientHydration()\` call. `,
506 ),
507 );
508 }
509
510 // invoking the original method
511 return (value as Function).apply(target, [headerName]);
512 };
513 },
514 });
515}
516
517function mapRequestOriginUrl(url: string, originMap: Record<string, string>): string {
518 const origin = new URL(url, 'resolve://').origin;

Callers 1

retrieveStateFromCacheFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…