Varnish not showing custom headers

In my Varnish 3 configuration (default.vcl) I configured the following to pass along information via the response headers:

sub vcl_deliver {
    if (obj.hits > 0) {
        set resp.http.X-Cache = "HIT";
        set resp.http.X-Cache-Hits = obj.hits;
    } else {
       set resp.http.X-Cache = "MISS";
    }
    set resp.http.X-Cache-Expires = resp.http.Expires;
    set resp.http.X-Test = "LOL";

    # remove Varnish/proxy header
    remove resp.http.X-Varnish;
    remove resp.http.Via;
    remove resp.http.Age;
    remove resp.http.X-Purge-URL;
    remove resp.http.X-Purge-Host;
    remove resp.http.X-Powered-By;
}

And yet the only thing I can see is

HTTP/1.1 200 OK
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Type: text/html
Content-Length: 8492
Accept-Ranges: bytes
Date: Tue, 05 Feb 2013 10:11:02 GMT
Connection: keep-alive

It doesn’t show any headers that we have added inside the vcl_deliver method.

EDIT: This is my vcl_fetch method:

sub vcl_fetch {
    unset beresp.http.Server;
    unset beresp.http.Etag;
    remove req.http.X-Forwarded-For;
    set req.http.X-Forwarded-For = req.http.rlnclientipaddr;
    set beresp.http.X-Wut = "YAY";

    if (req.url ~ "^/w00tw00t") {
        error 750 "Moved Temporarily";
    }

    # allow static files to be cached for 7 days
    # with a grace period of 1 day
    if (req.url ~ "\.(png|gif|jpeg|jpg|ico|swf|css|js)$") {
        set beresp.ttl = 7d;
        set beresp.grace = 1d;
        return(deliver);
    }

    # cache everythig else for 1 hours
    set beresp.ttl = 1h;

    # grace period of 1 day
    set beresp.grace = 1d;

    return(deliver);
}

Anyone got an idea how to solve this as NO custom headers are included in the response headers… As you can see above in my vcl_fetch method I add several custom response headers but none of they are showing.

Answer

vcl_deliver is only called for objects found in cache. You probably meant to use vcl_fetch.

If that’s not the issue, you don’t show the request you’re sending or your vcl_recv. Perhaps you’re pipeing, for example? Try sending a raw request via telnet or netcat and show us both what you sent and received. And since you’re using vcl_deliver, do the same request twice so we can debug properly, please.

Attribution
Source : Link , Question Author : Kenny , Answer Author : BMDan

Leave a Comment