Passing variable data to ESI requests

Guilhaume Bordiau gbordiau at work4labs.com
Mon Nov 12 16:18:31 CET 2012


Thanks Raul, but this doesn't work.

Here here is my basic test:

/////// default.vcl ///////
sub vcl_recv {
  if (req.url ~ "toto.php") {
    set req.http.X-toto = "42";
  }
  unset req.http.Cookie;
  return (pass);
}

sub vcl_fetch {
    set beresp.do_esi = true;
    return (deliver);
}

//////// toto.php /////////
<html>
<body>
<p>Parent headers:</p>
<pre>
<?php echo var_export($_SERVER, true) ?>
</pre>
<esi:include src="/esi.php" />
</body>
</html>

//////// esi.php /////////
<p>esi headers:</p>
<pre>
<?php echo var_export($_SERVER, true) ?>
</pre>

And as a result, when getting /toto.php, I can find the 'HTTP_X_TOTO' =>
'42' header in the parent header, but not in the ESI header.

Any idea?


On Thursday, November 8, 2012, Rangel, Raul wrote:

> Guilhaume,****
>
> There are a few tricks you can use to do this. First of all you can
> extract the cookie that you are interested in and place it in a header.***
> *
>
> ** **
>
> vcl_recv {****
>
>             set req.http.X-Cookie-One =
> regsub(req.http.Cookie,"^.*?mycookie=([^;]*);*.*$" , "\1");****
>
>             unset req.http.Cookie;****
>
> }****
>
> ** **
>
> Then when varnish does the request to the parent page you can completely
> ignore the X-Cookie-One header. As for the subsequent ESI requests they too
> should also have the X-Cookie-One header attached to them. In your back end
> you should be able to read the header and in the response include a Very:
> X-Cookie-One. This way you get per user caching on the ESI.****
>
> ** **
>
> Raul****
>
> ** **
>
> *From:* varnish-dev-bounces at varnish-cache.org <javascript:_e({}, 'cvml',
> 'varnish-dev-bounces at varnish-cache.org');> [mailto:
> varnish-dev-bounces at varnish-cache.org <javascript:_e({}, 'cvml',
> 'varnish-dev-bounces at varnish-cache.org');>] *On Behalf Of *Guilhaume
> Bordiau
> *Sent:* Thursday, November 08, 2012 3:42 AM
> *To:* varnish-dev at varnish-cache.org <javascript:_e({}, 'cvml',
> 'varnish-dev at varnish-cache.org');>
> *Subject:* Passing variable data to ESI requests****
>
> ** **
>
> Hello,****
>
> ** **
>
> We're using Varnish since a few weeks but are facing the issue of using
> dynamic content inside cached pages.****
>
> We tried ESI for that but it appears that there's no way to pass some (or
> all) of the original request elements (headers, cookies) to the ESI request
> made toward our server.****
>
> ** **
>
> We implemented hacks through cookies read from javascript, triggering ajax
> requests, but we're facing maintainability issues around browsers refusing
> cookies (our app run in an iframe and domains are different from the top
> frame).****
>
> ** **
>
> So we're starting to think of developing the missing part of code in
> Varnish that could make it do what we need: ****
>
> Allow to pass the original request headers and cookies to the ESI URI
> contained in a cached page.****
>
> ** **
>
> So my questions are:****
>
> - Can you confirm that's it's currently not possible?****
>
> - What would be the amount of work to achieve this?****
>
> - Any tips to help me getting started with this?****
>
> ** **
>
> Much thanks in advance to all.****
>
> ** **
>
> Guilhaume Bordiau.****
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20121112/42ae0d77/attachment.html>


More information about the varnish-dev mailing list