Search code examples
varnishvarnish-vcl

Is varnish casting boolean to string?


We have varnish 4.0.3 in a live environment. We extract this code from our vcl filein varnish vcl_recv:

set req.http.x-is-static-resource = true; #boolean assignment
# some code
if (req.http.x-is-static-resource == true) { # boolean == boolean ?
    # some code
}

But hits this error:

Message from VCC-compiler:
Comparison of different types: STRING '==' BOOL
('/etc/varnish/utils.vcl' Line 429 Pos 37)
  if (req.http.x-is-static-resource == true) {
------------------------------------##--------

We found this kind of assignments in several codes:

I think varnish shouldn't hits this error. We assign a boolean type and we expect a boolean type, right?

What are we missing?

Thanks


Solution

  • The assignments you found are not to req.http - req.http.[name] is a way to access the request header [name]. Headers are strings, not booleans. You can still make this work with small changes, though:

    set req.http.x-is-static-resource = "true";
    [...]
    
    if (req.http.x-is-static-resource) { [...]