Dynamically generating tracking images
Josh
josh at schulzone.org
Wed Oct 27 19:20:55 CEST 2010
You can't get access to the original query string unless you
specifically pass it along. The ESI passthrough is a totally new
disconnected request as far as the backend is concerned.
You should get cookies if the esi code could access them directly (IE:
On the same domain, path is OK). I havn't tried this, but based on
what I know about ESI it that's how it should work.
josh
On Wed, Oct 27, 2010 at 10:12 AM, Ruslan Sivak <russ at vshift.com> wrote:
> So I can't get access to the original query string? What about request
> cookies?
>
> Russ
>
> On Wed, Oct 27, 2010 at 1:05 PM, Josh <josh at schulzone.org> wrote:
>>
>> You have to put the query string parameters into the esi path:
>>
>> <esi:include
>> src="/esi/tracker.pl?url=ENTER+PAGE+URL+HERE&title=ENTER+PAGE+TITLE+HERE"/>
>>
>> I'm handling some tracking the exact same way, and it works fine. The
>> esi request is a separate hit to the backend and doesn't have any of
>> the context from the request that caused it.
>>
>> josh
>>
>> On Wed, Oct 27, 2010 at 9:51 AM, Ruslan Sivak <russ at vshift.com> wrote:
>> > We are building a site which needs to be cached, but we need to have a
>> > tracking image that gets output for every page. This image should
>> > contain
>> > certain (lets say all) parameters of the query string.
>> >
>> > I'm thinking of implementing this using ESI. I currently have the
>> > following:
>> >
>> > test.php
>> > <esi:include src="/esi/tracker.pl"/>
>> >
>> > /esi/tracker.pl
>> > #!/usr/bin/perl
>> > use CGI::Cookie ();
>> > use Apache2::RequestRec ();
>> > use APR::Table ();
>> > my $cookie = CGI::Cookie->new(-name => 'mod_perl',
>> > -value => 'awesome');
>> > print "Set-Cookie: $cookie\n";
>> > print "Content-type: text/html\n\n";
>> > print <<ENDHTML;
>> > $ENV{'QUERY_STRING'}
>> > <div>
>> > <img
>> >
>> > src="http://sometrackingsite/id/12345.gif?url=ENTER+PAGE+URL+HERE&title=ENTER+PAGE+TITLE+HERE"
>> > alt="" height="1" width="1" />
>> > </div>
>> > ENDHTML
>> >
>> > default.vcl
>> > ...
>> > sub vcl_fetch {
>> > set beresp.ttl=5d;
>> > if (req.url ~"test.php") {
>> > esi; /* Do ESI processing */
>> > set beresp.ttl = 24 h;
>> > } elseif (req.url == "/esi/tracker.pl") {
>> > set beresp.ttl = 1m;
>> > }
>> > if (beresp.http.set-cookie) {
>> > set beresp.http.set-cookie = ";" beresp.http.set-cookie;
>> > set beresp.http.set-cookie = regsuball(beresp.http.set-cookie, ";
>> > +",
>> > ";");
>> > set beresp.http.set-cookie = regsuball(beresp.http.set-cookie,
>> > ";(MY_COOKIE)=", "; \1=");
>> > set beresp.http.set-cookie = regsuball(beresp.http.set-cookie, ";[^
>> > ][^;]*", "");
>> > set beresp.http.set-cookie = regsuball(beresp.http.set-cookie, "^[;
>> > ]+|[; ]+$", "");
>> >
>> > if (beresp.http.set-cookie == "") {
>> > remove beresp.http.set-cookie;
>> > }
>> > return (deliver);
>> > }
>> > }
>> > ...
>> >
>> > Am I going about this the right way? Perl doesn't seem to see the query
>> > string or be able to set any cookies.
>> >
>> > Any help would be appreciated.
>> >
>> > Russ
>> >
>> > _______________________________________________
>> > varnish-misc mailing list
>> > varnish-misc at varnish-cache.org
>> > http://lists.varnish-cache.org/mailman/listinfo/varnish-misc
>> >
>>
>>
>>
>> --
>> josh
>> @schulz
>> http://schulzone.org
>>
>> _______________________________________________
>> varnish-misc mailing list
>> varnish-misc at varnish-cache.org
>> http://lists.varnish-cache.org/mailman/listinfo/varnish-misc
>
>
--
josh
@schulz
http://schulzone.org
More information about the varnish-misc
mailing list