Skip to content

Instantly share code, notes, and snippets.

@mardambey
Created August 27, 2010 02:56
Show Gist options
  • Save mardambey/552701 to your computer and use it in GitHub Desktop.
Save mardambey/552701 to your computer and use it in GitHub Desktop.
sub vcl_hash {
set req.hash += req.url;
set req.hash += req.http.host;
set req.http.X-Calc-Hash = "true";
if( req.http.Cookie ~ "JSESSIONID" ) {
set req.http.X-Varnish-Hashed-On =
regsub( req.http.Cookie, "^.*?JSESSIONID=([a-zA-z0-9]{32}\.[a-zA-Z0-9]+)([\s$\n])*.*?$", "\1" );
set req.hash += req.http.X-Varnish-Hashed-On;
}
return(hash);
}
@eternaltyro
Copy link

In case somebody stumbles upon this, Varnish has replaced req.hash with hash_data()

https://www.varnish-cache.org/docs/3.0/installation/upgrade.html#req-hash-is-replaced-with-hash-data

So this becomes

sub vcl_hash {
hash_data( req.url );
hash_data( req.http.host);
set req.http.X-Calc-Hash = "true";
if( req.http.Cookie ~ "JSESSIONID" ) {
set req.http.X-Varnish-Hashed-On = regsub( req.http.Cookie, "^.?JSESSIONID=([a-zA-z0-9]{32}.[a-zA-Z0-9]+)([\s$\n]).*?$", "\1" );
hash_data( req.http.X-Varnish-Hashed-On);
} return(hash); }

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