Skip to content

provideClientHydration() shouldn't cache HttpClient GET requests with "Authorization" header #54745

@aroncal

Description

@aroncal

Which @angular/* package(s) are relevant/related to the feature request?

common, platform-browser

Description

After I activated provideClientHydration() in my web application, I have noticed that GET requests from HttpClient are being cached internally by Angular, even if they are requests with "Authorization" headers. It's taken me a whole day to figure it out.

I've then tested with provideClientHydration(withNoHttpTransferCache()), and the extrange behavior stops happening. Nonetheless, I get the benefit of HttpClient caching when hydration is activated for GET requests without "Authorization" header. That being said, I'm finally trying the following configuration, which I think should be by default:

    provideClientHydration(withHttpTransferCacheOptions({
      filter: req => req.method === 'GET' && !req.headers.has('Authorization'),
    })),

Proposed solution

Stop provideClientHydration()from caching HttpClient's GET requests with "Authorization" header by default.

Alternatives considered

More documentation on how provideClientHydration() works along with HttpClient and caching.
Also, in the following links I don't get what the default behavior or filters are:
https://angular.io/api/platform-browser/withHttpTransferCacheOptions
https://angular.io/api/common/http/HttpTransferCacheOptions

Metadata

Metadata

Labels

P2The issue is important to a large percentage of users, with a workaroundarea: common/httpIssues related to HTTP and HTTP Clientserver: http cachetype: bug/fix

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions