Hashing on a particular cookie value
Soumendu Bhattacharya
soumendu_bhattacharya at non.agilent.com
Wed Nov 7 21:01:23 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
===================================================================
Thanks a lot Paul. Before I read this , I tried the following :
hash_data(regsub(req.http.Cookie,"^.*?mycookie=([^;]*);*.*$" , "\1"));
I guess this should also do the trick ?
Regards
Soumendu
More information about the varnish-misc
mailing list