Mailing List Archive

Question regarding vcl config
Hello all, I have inherited a varnish server. And I am a little confused
about a few lines in that config.

It has the following in vcl_recv

# Don't cache if there are request cookies
if (req.http.Cookie) {
set req.http.X-Debug-Varnish-Nocache-Recv = "Got request cookie ("
+ req.http.Cookie + ")";

return (pass);
}

if (req.url ~
"\.(png|gif|jpg|jpeg|ico|swf|css|js|pdf|ico|js|ogg|mp4)$") {
unset req.http.cookie;
}
if (req.url ~ "^/(includes|images|templates)") {
unset req.http.cookie;
}

So the first if block tells request with req.http.Cookie to pass to the
backend.
The second tells if the requested url ends with
.png|gif|jpg|jpeg|ico|swf|css|js|pdf|ico|js|ogg|mp4 and so on to unset the
cookie.
But will these rules be executed or is the request already passed to the
backend?

Thanks for your time
regards
Neuteboom
Re: Question regarding vcl config [ In reply to ]
On Sat, Sep 26, 2020 at 4:41 PM Johan Hendriks <neuteboom.log@gmail.com> wrote:
>
> Hello all, I have inherited a varnish server. And I am a little confused about a few lines in that config.
>
> It has the following in vcl_recv
>
> # Don't cache if there are request cookies
> if (req.http.Cookie) {
> set req.http.X-Debug-Varnish-Nocache-Recv = "Got request cookie (" + req.http.Cookie + ")";
>
> return (pass);
> }
>
> if (req.url ~ "\.(png|gif|jpg|jpeg|ico|swf|css|js|pdf|ico|js|ogg|mp4)$") {
> unset req.http.cookie;
> }
> if (req.url ~ "^/(includes|images|templates)") {
> unset req.http.cookie;
> }
>
> So the first if block tells request with req.http.Cookie to pass to the backend.
> The second tells if the requested url ends with .png|gif|jpg|jpeg|ico|swf|css|js|pdf|ico|js|ogg|mp4 and so on to unset the cookie.
> But will these rules be executed or is the request already passed to the backend?

The return(pass) statement will definitely prevent the following code
to be executed.

You might want to move the first if block after the two others, but
it's hard to tell without prior knowledge of how the backend
behaves...

Dridi
_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Question regarding vcl config [ In reply to ]
On Sat, Sep 26, 2020 at 8:31 PM Johan Hendriks <neuteboom.log@gmail.com> wrote:
>
> Thank you very much for your quick responce, so the order of the rules matter when you write vcl?
> I didn't know that, but it makes sense.

Yes, VCL is an imperative programming language and statements are
executed in order.

> I start some tests.
> Thanks again.

Please keep the mailing list CC'd if you have more questions.

Dridi
_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc