Hao
Hao

Reputation: 6609

Varnish acts differently on different browser, why?

On Firefox, Varnish is in play, but not on Google Chrome. Possible? Why?

Upvotes: 4

Views: 3379

Answers (3)

Nithish
Nithish

Reputation: 387

    if (req.http.Accept-Encoding) {
       if (req.http.Accept-Encoding ~ "gzip") {
           set req.http.Accept-Encoding = "gzip";
       } elsif (req.http.Accept-Encoding ~ "deflate") {
           set req.http.Accept-Encoding = "deflate";
       } else {
           # unknown language. Remove the accept-language header and
           # use the backend default.
           unset req.http.Accept-Encoding;
       }
    }
   //add below condition along with above code in vcl_recv subroutine.
   if(req.http.User-Agent) {
       unset req.http.User-Agent;
   }

Upvotes: 0

Christopher Cato
Christopher Cato

Reputation: 191

One other possible reason could be that you have a session cookie in Chrome that causes Varnish to pass the request to the backend.

Upvotes: 4

Mojah
Mojah

Reputation: 1373

The most likely cause is normalization of the Accept-Encoding header, both Firefox and Chrome send a different one. Add this to your sub vcl_recv():

if (req.http.Accept-Encoding) {
    if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
        # No point in compressing these
        remove req.http.Accept-Encoding;
    } elsif (req.http.Accept-Encoding ~ "gzip") {
        set req.http.Accept-Encoding = "gzip";
    } elsif (req.http.Accept-Encoding ~ "deflate") {
        set req.http.Accept-Encoding = "deflate";
    } else {
        # unkown algorithm
        remove req.http.Accept-Encoding;
    }
}

This is also documented in the Varnish manual on the "Vary" header.

Upvotes: 1

Related Questions