Skip to content

Instantly share code, notes, and snippets.

@simonwistow
Last active August 29, 2015 14:01
Show Gist options
  • Save simonwistow/2fa534508a3f6ae72508 to your computer and use it in GitHub Desktop.
Save simonwistow/2fa534508a3f6ae72508 to your computer and use it in GitHub Desktop.
Tracking cookies
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 force a miss
set req.hash_always_miss = true;
}
#FASTLY recv
}
sub vcl_fetch {
# The response has a Set-Cookie ...
if (beresp.http.Set-Cookie) {
# ... so store it temporarily
set req.http.Tmp-Set-Cookie = beresp.http.Set-Cookie;
# ... and then unset it
unset beresp.http.Set-Cookie;
}
#FASTLY fetch
}
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
}
@samjsharpe
Copy link

I can't believe Github doesn't have a VCL type for gists, calling this a perl file seems super-icky

@simonwistow
Copy link
Author

@samjsharpe - yeah, yet it oddly works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment