Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surrogate-Control headers #11

Open
ryanschneider opened this issue May 3, 2018 · 2 comments
Open

Surrogate-Control headers #11

ryanschneider opened this issue May 3, 2018 · 2 comments

Comments

@ryanschneider
Copy link

It looks like this package does not support the less common Surrogate-Control header sometimes used by CDNs.

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

See nicolasazrak/caddy-cache#24 for discussion.

@pquerna
Copy link
Owner

pquerna commented May 3, 2018

I think basic support could be done today using the low level api, eg by populating Object.RespDirectives with the parsed results of ParseResponseCacheControl(respHeaders.Get("Surrogate-Control")):
https://godoc.org/github.com/pquerna/cachecontrol/cacheobject#Object

Having said that, adding a field to the options object would also let this work using the high level API and remain compatible with existing API users too:
https://godoc.org/github.com/pquerna/cachecontrol#Options

@ryanschneider
Copy link
Author

Ya, I was looking in those areas, my naive first pass was to update UsingRequestReponse like so:

        var reqDir *RequestCacheDirectives = nil
	ctrlHeader := "Cache-Control"
	if respHeaders.Get("Surrogate-Control") != "" {
		ctrlHeader = "Surrogate-Control"
	}

	respDir, err := ParseResponseCacheControl(respHeaders.Get(ctrlHeader))
	if err != nil {
		return nil, time.Time{}, err
	}

Which is to say, use the Surrogate-Control header if its there, otherwise fallback to Cache-Control, but I agree that making it controllable via Options would be good, so I'll look into how that could be done.

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

No branches or pull requests

2 participants