跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

Headers not transferred by HttpTransferCache ​

Angular produces this warning when code attempts to access an HTTP header that was not transferred from the server to the client by the HttpTransferCache.

By default, HttpTransferCache does not transfer any headers to avoid potential security issues or unnecessary data transfer. When a header is accessed on the client that wasn't included, Angular logs this warning to help you identify missing headers.

Fixing the error ​

To include specific headers in the transfer cache, use the includeHeaders option.

At the request level ​

Add the transferCache parameter to your HTTP request:

ts
this.http.get('/api/data', {
  transferCache: {
    includeHeaders: ['cache-control', 'etag'],
  },
});

At the application level ​

Configure includeHeaders when providing the transfer cache:

ts
provideClientHydration(
  withHttpTransferCacheOptions({
    includeHeaders: ['cache-control', 'etag'],
  }),
);

Only include headers that are necessary for your application logic. Be cautious with sensitive headers.

Debugging the error ​

The warning message includes the header name and the request URL. Check your code for where this header is being accessed and determine if it needs to be included in the transfer cache.

If the header is not needed on the client, consider refactoring your code to avoid accessing it.

基于 MIT 许可证发布。