Ignoring GET parameters in Varnish VCL
Posted
by JamesHarrison
on Server Fault
See other posts from Server Fault
or by JamesHarrison
Published on 2010-02-13T12:08:42Z
Indexed on
2010/03/16
17:41 UTC
Read the original article
Hit count: 461
Okay: I've got a site set up which has some APIs we expose to developers, which are in the format
/api/item.xml?type_ids=34,35,37®ion_ids=1000002,1000003&key=SOMERANDOMALPHANUM
In this URI, type_ids is always set, region_ids and key are optional.
The important thing to note is that the key variable does not affect the content of the response. It is used for internal tracking of requests so we can identify people who make slow or otherwise unwanted requests.
In Varnish, we have a VCL like this:
if (req.http.host ~ "the-site-in-question.com") {
if (req.url ~ "^/api/.+\.xml") {
unset req.http.cookie;
}
}
We just strip cookies out and let the backend do the rest as far as times are concerned (this is a hackaround since Rails/authlogic sends session cookies with API responses).
At present though, any distinct developers are basically hitting different caches since &key=SOMEALPHANUM
is considered as part of the Varnish hash for storage. This is obviously not a great solution and I'm trying to work out how to tell Varnish to ignore that part of the URI.
© Server Fault or respective owner