Varnish regular expression evaluated at compile time.
Hugues Alary
hugues.alary at gmail.com
Thu Oct 11 01:14:03 CEST 2012
Hi Paul,
Thank you for your answer, and your idea. It is a very good idea I didn't
think of.
I don't know if it's gonna be the solution I'll adopt, but at this very
moment I only have that or coding a vmod. However I don't think that coding
a vmod is a solution as I would just implement something (regular
expression evaluation at run time) that phk says being too expensive.
-Hugues
On Wed, Oct 10, 2012 at 3:59 PM, Paul A. Procacci <pprocacci at datapipe.com>wrote:
> 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.
>
--
Hugues ALARY
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20121010/97d89652/attachment.html>
More information about the varnish-misc
mailing list