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

Ignore VARY response header? #593

Open
teodorescuserban opened this issue Jan 21, 2025 · 2 comments
Open

Ignore VARY response header? #593

teodorescuserban opened this issue Jan 21, 2025 · 2 comments

Comments

@teodorescuserban
Copy link

Hello, I am using the souin module with caddy and redis (see versions below).

I am using {http.request.uri} as the cache key and everything seems to be running properly.
However, it looks like if the response contains a Vary header, the cache key will also include this header value automatically.

I solved this issue by just adding a headers_down -Vary in the reverse proxy block, but I would really like to pass the response with all headers.

Would it be possible to ignore the Vary header in the cache config?

Thank you!

/etc/caddy # caddy version
v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=
/etc/caddy # caddy build-info | grep souin
dep     github.com/darkweak/souin       v1.7.5  h1:drNhZc0GhSbGcugiGfcYdLDTcx3DCZW6o13wwRj5o5Y=
/etc/caddy # caddy build-info | grep stora
dep     github.com/darkweak/storages/core       v0.0.11 h1:IwvpAtkhOmxC5pIffJ8opW6erpTnIi5zqPveiAQs8ew=
dep     github.com/darkweak/storages/go-redis   v0.0.11 h1:2IjIEPREWyooSAq4syKeFq/yeia5sPnaypzs/GK3tRo=
dep     github.com/darkweak/storages/go-redis/caddy     v0.0.11 h1:d6qQRAzOJLSmQkLXEW/XVTAkh/C0kofPP3LxoP9djWs=

For example, for this request:
/v3/viewSummary?loc=20
the response contains the header:
vary: origin,access-control-request-method,access-control-request-headers
and the cache key becomes:
/v3/viewSummary?loc=20{-VARY-}origin:;access-control-request-method:;access-control-request-headers:"

This is my cache configuration:

cache {
	cache_name cache
	allowed_http_verbs GET HEAD
	api {
		debug
		prometheus
		souin
	}
	log_level info
	# see https://github.com/darkweak/souin/issues/345#issuecomment-1560574770
	mode bypass
	ttl 30s # 3h
	stale 1s # 72h
	timeout {
		backend 300s
		cache 120s
	}
	default_cache_control public
	key {
		template {http.request.uri}
		# hash
	}
	redis {
		configuration {
			Addrs redis:6379
			DB 4
		}
	}
}

@darkweak
Copy link
Owner

Hello @teodorescuserban we can introduce a new configuration directive named disable_vary in the key and cache_keys.

@teodorescuserban
Copy link
Author

Hello @teodorescuserban we can introduce a new configuration directive named disable_vary in the key and cache_keys.

That would be awesome, @darkweak!
In the mean time, I'm keeping the headers_down -Vary config.

One note though, I think the disable_* options are skipped if template is being used. This means disable_vary would need a slightly different logic so it remains enabled even if template is used

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