Skip to content
This repository has been archived by the owner on Apr 18, 2021. It is now read-only.

Cache should honor Surrogate-Control response headers as well #24

Open
ryanschneider opened this issue Apr 13, 2018 · 8 comments
Open

Comments

@ryanschneider
Copy link

The logic to support Surrogate-Control would basically the same as Cache-Control, but the header is specifically meant for reverse proxy <-> origin server controls (Cache-Control is meant for end browsers)

See: https://www.w3.org/TR/edge-arch/

Often used by CDNs:
https://docs.fastly.com/guides/tutorials/cache-control-tutorial
https://www.nuevocloud.com/documentation/getting-started/cache-headers-cache-control-surrogate-control-and-expires

One caveat: It's not clear to me if it'd the cache plugins job to strip the Surrogate-Control header from the response, or if that should be handled by the proxy plugin.

@ryanschneider
Copy link
Author

Testing some more, I think cache does need to remove the Surrogate-Control header, since if proxy removes it the cache doesn't see it.

@nicolasazrak
Copy link
Owner

To be honest I didn't knew it existed. It shouldn't be hard to implement, it's just a change in the rules logic (https://github.com/nicolasazrak/caddy-cache/blob/master/rules.go). I don't have much time right now but I'll try to implement it in a few days if I can.

@ryanschneider
Copy link
Author

ryanschneider commented Apr 17, 2018 via email

@ryanschneider
Copy link
Author

I finally spent some time looking at this more, and realized it actually needs to be added to the cachecontrol package upstream, so I'll open an issue there and see if I can add it.

@pquerna
Copy link

pquerna commented May 3, 2018

(upstream package here)

BTW, I'm generally fine adding support for this in cachecontrol, but as someone who has been doing http caching for a long time, I wasn't familiar with Surrogate-Control. Its not supported by nginx/apache/etc.

So, I'm not opposed to supporting it, I was just wondering if there is a real world origin you are trying to support that outputs these?

Yes, I see that varnish & fastly have been promoting more use of it, but besides a 2001 w3c note, it is notability absent from things like rfc7234

I wonder if @mnot has commentary about Surrogate-Control?

@ryanschneider
Copy link
Author

Our in-house origin does, because we added it for our CDN, which I'm now looking to replace with our own edge servers, and was building a proof of concept with Caddy.

It is nice in that it's not passed to end-user browsers, so you can have separate CDN and end-user caching strategies, but I agree 100% it's pretty niche.

@nicolasazrak
Copy link
Owner

I'm in favor of adding any feature as long as it doesn't add complexity to the project, which seems to be the case. For this package, I think it's just a matter of upgrading the cache-control version when the support for Surrogate-Control is implemented and removing the header from the response if it's present. So unless I'm missing something this should be a pretty trivial change.

@mnot
Copy link

mnot commented May 7, 2018

It's also supported by Akamai and other CDNs. That is not one of my favourite specs (sorry), but it does see deployment.

I'm half-tempted to write an updated spec and come up with some tests.

It would be good for frameworks to support it, so that they can interop with CDNs better; I've been trying to get CDNs to become more standardised in how they handle HTTP, so this would help (I think).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants