Hashing on a particular cookie value
Paul A. Procacci
pprocacci at datapipe.com
Wed Nov 7 18:37:55 CET 2012
On Wed, Nov 07, 2012 at 10:18:45PM +0530, Soumendu Bhattacharya wrote:
> Hi All,
>
> I am trying to hash varnish on a particular cookie
> value. My url remains the same , but the content changes depending on
> if you have this particular cookie and its value. I am stuck at how to
> evaluate that cookie value and pass it to hash function (passing it to
> hash function is not a problem - but how to evaluate the cookie value).
>
>
> Can this be done in default Varnish ?
>
> Any help will be greatly appreciated.
The following (untested) snippet might be what you are looking for?
##############################
sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
if (req.http.cookie ~ "mycookie=") {
set req.http.X-TMP = regsub(req.http.cookie, ".*mycookie=([^;]+);.*", "\1");
hash_data(req.http.X-TMP);
remove req.http.X-TMP;
}
return (hash);
}
##############################
The `req` object is available for you to mess with in vcl_hash.
~Paul
________________________________
This message may contain confidential or privileged information. If you are not the intended recipient, please advise us immediately and delete this message. See http://www.datapipe.com/legal/email_disclaimer/ for further information on confidentiality and the risks of non-secure electronic communication. If you cannot access these links, please notify us by reply message and we will send the contents to you.
More information about the varnish-misc
mailing list