basante
basante

Reputation: 545

Testing varnish cache rule

I have this:

if (bereq.http.X-Path ~ "[a-z0-9]+\.(js|css)$") {
            set beresp.http.Cache-Control = "max-age=259200";
    }

And I need to write a test.vtl to demonstrate that is working. I'm trying with:

client c1 {
    txreq -url "/content/css/main.min.aer234vcvb.css"
    rxresp
} -run

But it fails.

Upvotes: 1

Views: 395

Answers (1)

Helmut Januschka
Helmut Januschka

Reputation: 1636

the problem is that you - match your condition on X-Path incomming http header. therefore in your client you are not sending it in, and the condition just does not match.

see this sample, based on your config, but sending in X-Path.

varnishtest "Test Cache-Control on X-Path"

server s1 {
    rxreq
    txresp
} -start

varnish v1 -vcl+backend { 

  sub vcl_backend_response {
        if (bereq.http.X-Path ~ "[a-z0-9]+\.(js|css)$") {
           set beresp.http.Cache-Control = "max-age=259200";
    }
  }

} -start

client c1 {
    txreq -url "/content/css/main.min.aer234vcvb.css" -hdr "X-Path: /content/css/main.min.aer234vcvb.css"
    rxresp
    expect resp.http.Cache-Control == "max-age=259200"
} -run

you might want to check against bereq.url and not bereq.http.X-Path ?!

Upvotes: 1

Related Questions