4

I'm trying to work out varnish.

My problem is. I do have a main request/response which I want to cache using varnish. Inside html structure a have ESI tag. I want to have many of them. One tag with longer ttls and others with ttl=0s; (ESI content with login box).

Anyway, I want varnish to hit the main request, but ask backend ESI content for some info like headers. When ESI content comes back (cause I understand first is parent request, then are sub request with ESI), I want to have some kind of communication.

Remember that changes made to beresp are stored in obj afterwards. And the resp.* variables are copies of what’s about to be returned - possibly of obj. A change to beresp will, in other words, affect future obj.* and resp.* variables. Similar semantics apply to req.* and bereq.. bereq. is the “backend request” as created from the original request. It may differ slightly - Varnish can convert HEAD requests to GET for example.

from https://www.varnish-software.com/static/book/VCL_functions.html

For example: If ESI subrequest has header "X-ESI-Cookie" on response, I want to pass it to main response.

The only way I can find out anything about the ESI is reg.esi_level.

if (req.esi_level > 0 ) {
    set req.http.*;
}

Basically what I want to achieve is that:

I want varnish to cache my whole page, but for session management pipe the ESI content, but to preserve session I need pass some headers from sub (ESI) to parent response (but I believe that's obvious).

I believe the varnish requests (parent and ESI's) are taken care separately, which means I won't have any chance to communicate. Varnish simply replace tag with html from ESI response. Is it so?

I'm starting to believe that there's no solution for that, but maybe someone has better solution for this problem: How to preserve session? I found some solutions, but no one fits my needs. (I believed with Fake-Session, whre ID was generated by Varnish with some C code, but with no lock).

I want to do this in that way because it would be much easier for me to adopt current symfony2 app. Anyway I can't believe that symfony2 didn't expect this kind of feature. My pages are mainly static besides few widgets (ESI content).

It would be very nice though to have ESI content (request, content and response) to object variable:

obj.*

I cannot believe the varnish object does not have any information about ESI content.

It is important to notice that I am looking for solution in *.vcl configuration, but any solution will work for me.

Thanks in advance.

1 Answers1

0

It is possible to parse variables from the main request to ESI subrequests using libvmod-var, this is however not really documented, but it works fine in the current version of libvmod-var and varnish 3.0.6.

Christian
  • 908
  • 1
  • 13
  • 22