if (req.restarts == 0) VCL Error

Tim Dunphy bluethundr at gmail.com
Wed May 7 04:27:05 CEST 2014


Hey All,

 I'm trying to write a VCL subroutine. The purpose of the section I am
having a problem with is to set some headers when it encounters a restart
condition. Here's the code.

sub vcl_recv {
    if (req.restarts == 0) {
      if (req.http.x-forwarded-for) {
           set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " +
client.ip;
       } else {
       set req.http.X-Forwarded-For = client.ip;  }
    }

    if (req.request != "GET"&&req.request != "HEAD") {
      return (pass);
    }

    set req.backend = www;
}

And here is the error I'm getting:

[root at varnish1 varnish]# varnishd -C -f default.vcl
Message from VCC-compiler:
Syntax error at
('input' Line 39 Pos 30)
    if (req.restarts == 0) {
-----------------------------#-

Running VCC-compiler failed, exit 1

VCL compilation failed

I'm not entirely sure why, but it looks as if the phrase:

if (req.restarts == 0)

Is causing it to error out.

If I remove that one condition, the VCL does work! So if we're left with
just:

sub vcl_recv {

    if (req.request != "GET"&&req.request != "HEAD") {
      return (pass);
    }

    set req.backend = www;

In the sub vcl looks like we're ok!

[root at varnish1 varnish]# service varnish reload
Loading vcl from /etc/varnish/default.vcl
Current running config name is reload_2014-05-06T22:13:17
Using new config name reload_2014-05-06T22:26:27
VCL compiled.

available       0 boot
available       6 reload_2014-05-06T22:13:17
active          0 reload_2014-05-06T22:26:27

Done

I would definitely appreciate any advice you may have as to why the above
condition is not working.

Thanks,
Tim



-- 
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20140506/d0735229/attachment.html>


More information about the varnish-misc mailing list