Check body length in VCL

T. Pascal t_pascal at zennet.com
Wed Aug 11 23:41:04 CEST 2010


On Wed, Aug 11, 2010 at 1:40 PM, Poul-Henning Kamp <phk at phk.freebsd.dk> wrote:
> In message <AANLkTimHL7J-pN1NWiqYMPqdjt21aRGcZNoioHEgHrHH at mail.gmail.com>, "T.
> Pascal" writes:
>
>>if ((beresp.status == 200) && (length(body) > 3000)) {
>
> The trouble is that vcl_fetch is called before the body is fetched
> from the backend, so we cannot know the length, if the transfer
> method is EOF or chunked...
>
I suppose that I intuited as much and so I cast around a bit to think
that maybe the body is available:

sub vcl_deliver {
        if ((resp.status == 200) && (resp.http.Content-Length ~ "\d{5}")) {
                set obj.ttl = 10d;
        }
}

Of course, my luck ended there:

Message from VCC-compiler:
Variable 'obj.ttl' not accessible in method 'vcl_deliver'.
At: (input Line --- Pos 21)
                set obj.ttl = 10d;
--------------------#######-------
Running VCC-compiler failed, exit 1

I suppose it is a vicious circle that "the body is not available when
we can update the ttl" and "the ttl cannot be updated when the body is
available".

There might be a use case to update the TTL at times other than
vcl_fetch?  Why not be able to update the TTL when we deliver content
(thus creating a sort of MRU)?

-T.




More information about the varnish-dev mailing list