Varnish regular expression evaluated at compile time.

Paul A. Procacci pprocacci at datapipe.com
Thu Oct 11 00:59:25 CEST 2012


Everything you stated is true.  Without inline C or a vmod
the only alternative I know of to accomplish this would be
to dynamically generate the parts of your config that
depend on the sha1 of a url.

For instance, you could use something similar to the following:

#################################################
#!/usr/bin/perl -w

use strict;
use Digest::SHA qw(sha1_hex);

my @files = qw!/index.html /homepage.html!;

my $output;
my $seen = 0;
foreach(@files){
  if($seen++){
    $output .= "else";
  }
  $output .= "if(req.url == \"$_\"){\n";
  $output .= "  set resp.http.Set-Cookie = \"foo" . sha1_hex($_) . "=\" + random.get_rand();\n";
  $output .= "}\n"
}

print $output;
#################################################

Modified to your liking obviously, which results in the following
output:

#################################################
if(req.url == "/index.html"){
  set resp.http.Set-Cookie = "foo14fe4559026d4c5b5eb530ee70300c52d99e70d7=" + random.get_rand();
}
elseif(req.url == "/homepage.html"){
  set resp.http.Set-Cookie = "foo6593125bb8fade312b1081d4ee1998f316aa4081=" + random.get_rand();
}
#################################################

This has the benefit that everything with exception to the random
number is computed ahead of time, but has the drawback of having
to use in this case, another script to maintain a list of
accessible files to generate their hash.

Honestly not sure if this is going to help or not, but
maybe it'll give you other ideas to explore.

~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