Skip to content

Instantly share code, notes, and snippets.

@eiriksm
Created Nov 26, 2014
Embed
What would you like to do?
outtakes.vcl
sub vcl_recv {
# ... some other stuff and logic.
# This is so special I keep it in a separate if block.
if (req.http.host == "orkjern.com") {
# These first lines are based on lullabot's setup. Google it.
set req.http.Cookie = ";" + req.http.Cookie;
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
# This cookie gets set from javascript.
if (req.http.Cookie ~ "ORKJERN_THEME_CACHE") {
set req.http.Cookie = ";" + req.http.Cookie;
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
set req.http.Cookie = regsuball(req.http.Cookie, ";(ORKJERN_THEME_CACHE=[0-9]*)", " \1=");
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
# Now all of the visitors with the theme cache key will get the same
# URL (used as hash for caches). Something like xxx.com/node/1?has_cache=true&cookie=ORKJERN_THEME_CACHE123456
set req.url = req.url + "?has_cache=true&cookie=" + req.http.Cookie;
}
else {
# All visitors without the theme cache hook will also get the same hash.
set req.url = req.url + "?has_no_cache=true&cookie=" + req.http.Cookie;
}
# No-one gets to use cookies on the site, resulting in no-one being able to log in.
unset req.http.Cookie;
# ... and so on with other logic.
}
}
# Also this:
sub vcl_deliver {
# Useful for debugging:
set resp.http.X-URL = req.url;
## ... and then some other things.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment