Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do HTTP proxy caches decide between serving identity- vs. gzip-encoded resources?

An HTTP server uses content-negotiation to serve a single URL identity- or gzip-encoded based on the client's Accept-Encoding header.

Now say we have a proxy cache like squid between clients and the httpd.

If the proxy has cached both encodings of a URL, how does it determine which to serve?

The non-gzip instance (not originally served with Vary) can be served to any client, but the encoded instances (having Vary: Accept-Encoding) can only be sent to a clients with the identical Accept-Encoding header value as was used in the original request.

E.g. Opera sends "deflate, gzip, x-gzip, identity, *;q=0" but IE8 sends "gzip, deflate". According to the spec, then, caches shouldn't share content-encoded caches between the two browsers. Is this true?

like image 232
Steve Clay Avatar asked Mar 29 '09 16:03

Steve Clay


2 Answers

First of all, it's IMHO incorrect not to send "Vary: Accept-Encoding" when the entity indeed varies by that header (or its absence).

That being said, the spec currently indeed disallows serving the cached response to Opera, because the Vary header does not match per the definitions in HTTPbis, Part 6, Section 2.6. Maybe this is an area where we should relax the requirements for caches (you may want to follow up on the IETF HTTP mailing list...

UPDATE: turns out that this was already marked as an open question; I just added an issue in our issue tracker for it, see Issue 147.

like image 157
Julian Reschke Avatar answered Nov 13 '22 13:11

Julian Reschke


Julian is right, of course. Lesson: Always send Vary: Accept-Encoding when sniffing Accept-Encoding, no matter what the response encoding.

To answer my question, if you mistakenly leave Vary out, if a proxy receives a non-encoded response (without Vary), it can simply cache and return this for every subsequent request (ignoring Accept-Encoding). Squid does this.

like image 2
Steve Clay Avatar answered Nov 13 '22 12:11

Steve Clay