I’ve written a Varnish module (VMOD) to simplify handling of HTTP cookies in Varnish VCL.
In essence it does the usual stuff you’d usually do with regular expressions, but with much simpler syntax and readability.
It works by parsing the req.http.Cookie into a small data structure. Afterwards you can add/delete/filter the list, and finally ask for a combined string back again.
Here is the list of functions:
- cookie.parse(cookiestring) – parse the http.req.Cookie string.
- cookie.get(cookiename) – get the value of a single parsed cookie.
- cookie.set(cookiename, cookievalue) – set the value of a cookie.
- cookie.delete(cookiename) – delete a single cookie.
- cookie.filter_except(filterstring). Delete all cookies but the ones matching the names in the comma-separated filterstring (“cookie1,cookie2,cookie3”.) This should be quite useful.
- cookie.get_string() – return the parsed string.
You can find it here: