manipulating page content
Laurence Rowe
l at lrowe.co.uk
Wed May 12 22:41:01 CEST 2010
On 12 May 2010 08:40, Rob Brown <dtownrobbrown at gmail.com> wrote:
>> If we are talking about stuff in the body of the object, the anwer is
>> no.
>
>
> yes, unfortunately that is what I am looking for. I am trying to see if
> varnish can "replicate" the functionality of a commercial cache appliance
> from a "well-known" vendor.
>
>>
>> You could always use ESI for it, but apart from that, there's currently
>> no way to manipulate the content of a page.
>
> ESI would probably work and be much easier, but reading the wiki
> (http://varnish-cache.org/wiki/ESIfeatures) it seems like Varnish doesn't
> yet support the "Content substitution based on variables" functionality.
> I am not well versed in ESI, but I think would be looking to do something
> like this:
> <esi:vars>
> <a
> href="http://www.example.com/getpage?sessionKey=$(QUERY_STRING{'sessionKey'})"/>get
> page</a>
> </esi:vars>
> In the wiki, it says "For now we have deemed this feature uninteresting, but
> adding it is just a matter of programming." What are the chances of getting
> support for variables in a future release?
It might be possible to make this work with just ESI includes.
Assuming that the ESI subrequests reuse the same req object as the
parent request (I'm not sure about this point), all you need do is
generate the key as a synthetic response in vcl_error. Something like:
sub vcl_recv {
if (req.url == "/_esi/sessionKey") {
error 701;
} else {
set req.http.X-Session-Key = # regexp to extract session key from url
}
}
sub vcl_error {
if (obj.status == 701) {
synthetic {
"<a href=%34http://www.example.com/getpage?sessionKey="
req.http.X-Session-Key "%34>get page</a>"
};
}
}
And use in your page:
<esi:include src="/_esi/sessionKey"/>
Laurence
More information about the varnish-misc
mailing list