[Varnish] #1062: Cannot test response header emptiness in varnishtest

Varnish varnish-bugs at varnish-cache.org
Fri Nov 18 17:29:09 CET 2011

#1062: Cannot test response header emptiness in varnishtest
 Reporter:  ofavre                               |        Type:  defect     
   Status:  new                                  |    Priority:  normal     
Milestone:                                       |   Component:  varnishtest
  Version:  3.0.2                                |    Severity:  normal     
 Keywords:  expect varnishtest vtc header empty  |  
 Consider the following test:
 varnishtest "Varnishtest bug: bad substitution with quoted values with

 server s1 {
 } -start

 varnish v1 -vcl+backend {
         sub vcl_deliver {
                 # Test with, and without the following line
                 set resp.http.X-Test = "a";
 } -start

 client c1 {
         expect resp.http.X-Test == "a"
         expect resp.http.X-Test != "resp.http.X-Test"
 } -run

 The expect command does a replacement (using cmd_var_resolve()) in the LHS
 and RHS site, the enclosing double-quotes are ignored.

 Therefore it is impossible to test for a header emptiness:
 If the header exists (and is equal to "a"), the two tests are equivalent
 assert(strcmp("a", "a") == 0);
 assert(strcmp("a", "a") != 0); // instead of assert(strcmp("a",
 "resp.http.X-Test") != 0);
 If the header doesn't exist, the two tests are equivalent to:
 assert(strcmp("resp.http.X-Test", "a") == 0);
 assert(strcmp("resp.http.X-Test", "resp.http.X-Test") != 0); // instead of
 assert(strcmp(NULL, "resp.http.X-Test") != 0);

 === Here are a few possible fixes: ===

 - Changing the language in order to make it respect double quoted strings,
 and maybe honor macro replacements like ${var} ;

 - Permit running the test would be to '''implement the "~" test''' (a
 third case in varnishtest/vtc_http.c:cmd_http_expect()) using a regex ;

 - In varnishtest/vtc_http.c:cmd_var_resolve(): if spec matches
 req/resp.http. and http_find_header() doesn't find the header and returns
 NULL, return NULL or "".

Ticket URL: <https://www.varnish-cache.org/trac/ticket/1062>
Varnish <https://varnish-cache.org/>
The Varnish HTTP Accelerator

More information about the varnish-bugs mailing list