pomo
pomo

Reputation: 2301

setting the Vary head from firebase function

I'm unable to successfully set the Vary header in a firebase function.

My code:

res.set('Vary', 'Accept-Encoding');

Server response:

vary: x-fh-requested-host, accept-encoding, cookie, authorization

I have several functions that return data that I want cached based purely on the 'Accept-Encoding' header. But no matter what I do, firebase appears to overwrite my header with its own. Crucially, it's adding cookie, authorization which break my cache.

My functions are accessed by a url that is rewritten using firebase hosting. According to these docs it should be possible.

Upvotes: 0

Views: 641

Answers (1)

Michael Bleigh
Michael Bleigh

Reputation: 26333

Firebase Hosting automatically adds these headers to Vary to prevent accidental cross-user cache leaks. This can still work perfectly well with caching, as Firebase Hosting also strips all cookies from the Cookie header except one named __session.

If you have content that does not vary based on the Authorization header, I'd recommend not including that header in your request to the function (since your function should not be using it anyway unless it's part of the Vary).

Upvotes: 3

Related Questions