简体   繁体   中英

Combining headers in Varnish

I'm running multiple Varnish cache servers on top of each other. I want to "combine" the headers of each of them, that is, when I make a request to my website, I can see which cache server it had a hit on. Right now, both of the cache servers have this code:


sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #
    # You can do accounting or modifying the final object here.
    if (obj.hits > 0) {
            set resp.http.X-Cache = "HIT";
    } else {
            set resp.http.X-Cache = "MISS";
    }
}

On my second cache server, I'd like the have something like this:

sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #
    # You can do accounting or modifying the final object here.
    if (obj.hits > 0) {
            set resp.http.X-Cache = "HIT, " + responsefromfirst;
    } else {
            set resp.http.X-Cache = "MISS, " + responsefromfirst;
    }
}

With responsefromfirst being the "X-Cache" header from the previous cache. How can I do this?

how about

sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #
    # You can do accounting or modifying the final object here.
    if (obj.hits > 0) {
            set resp.http.X-Cache = "HIT, " + resp.http.X-Cache;
    } else {
            set resp.http.X-Cache = "MISS, " + resp.http.X-Cache;
    }
}

you really just want to prepend information to header that is already there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM