dutchcoders / transfer.sh

Easy and fast file sharing from the command-line.
https://github.com/dutchcoders/transfer.sh
MIT License
15.25k stars 1.54k forks source link

Add `Vary` headers in responses #536

Closed kotx closed 1 year ago

kotx commented 1 year ago

This prevents caching servers like Cloudflare from caching responses when Accept or X-Decrypt-Password request headers vary. Before this, servers like Cloudflare would cache the html preview page regardless of Accept header (meaning curls and non-browser requests would also return a cached preview page). Adding a Vary header should prevent that.

More info here: https://blog.cloudflare.com/vary-for-images-serve-the-correct-images-to-the-correct-browsers/

aspacca commented 1 year ago

More info here: https://blog.cloudflare.com/vary-for-images-serve-the-correct-images-to-the-correct-browsers/

I'm not 100% sure about the cloudflare behaviour on the Vary header: the article mentions only Accept, is just for the sake of the example?

If not, and they only "react" to Accept it seems to me that they are forcing the upstream service behind their cache to send a value that does not respect the real ones that should be set: in this case I would set the proper ones, and if it still does not work with cloudflare cache please ask them to fix ;)

kotx commented 1 year ago

More info here: https://blog.cloudflare.com/vary-for-images-serve-the-correct-images-to-the-correct-browsers/

I'm not 100% sure about the cloudflare behaviour on the Vary header: the article mentions only Accept, is just for the sake of the example?

I've only just discovered this, but apparently Cloudflare only allows Vary for images on the non-free plans? :(

But normally, Cloudflare and any server should not cache if the headers in Vary are different.

aspacca commented 1 year ago

But normally, Cloudflare and any server should not cache if the headers in Vary are different.

yes, I'm fine adding the Vary header, just I won't implement it to make cloudflare happy, but according to the rfc :)

aspacca commented 1 year ago

@kotx could you please merge the main branch on yours? thanks

kotx commented 1 year ago

could you please merge the main branch on yours? thanks

Done, hope this works