Last active
August 29, 2015 14:01
-
-
Save simonwistow/17c5ec92816149d8bed6 to your computer and use it in GitHub Desktop.
Tracking cookie create
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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