Skip to content

Instantly share code, notes, and snippets.

@simonwistow
Last active August 29, 2015 14:01
Show Gist options
  • Save simonwistow/17c5ec92816149d8bed6 to your computer and use it in GitHub Desktop.
Save simonwistow/17c5ec92816149d8bed6 to your computer and use it in GitHub Desktop.
Tracking cookie create
sub vcl_recv {
if (req.http.Cookie ~ "mycookie=") {
# The request does have a tracking cookie so store it temporarily
set req.http.Tmp-Set-Cookie = req.http.Cookie;
unset req.http.Cookie;
} else {
# The request doesn't have a tracking cookie so create one
set req.http.Tmp-Set-Cookie = if(req.http.Cookie, req.http.Cookie "; ", "") "mycookie=" digest.hash_md5(now randomstr(32) client.ip);
}
#FASTLY recv
}
sub vcl_deliver {
# Send the Cookie header again if we have it
if (req.http.Tmp-Set-Cookie) {
set resp.http.Set-Cookie = req.http.Tmp-Set-Cookie;
}
#FASTLY deliver
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment