]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compression: automatically disable compression for older browsers
authorWilly Tarreau <w@1wt.eu>
Fri, 26 Oct 2012 00:11:25 +0000 (02:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 26 Oct 2012 00:54:31 +0000 (02:54 +0200)
A number of older browsers have many issues with compressed contents. It
happens that all these older browsers announce themselves as "Mozilla/4"
and that despite not being all broken, the amount of working browsers
announcing themselves this way compared to all other ones is so tiny
that it's not worth wasting cycles trying to adapt to every specific
one.

So let's simply disable compression for these older browsers.

More information on this very detailed article :

   http://zoompf.com/2012/02/lose-the-wait-http-compression

src/proto_http.c

index 720d66bf3e456e5ce0a23b804bc45d8dd883ea68..9b094d732cd7e32cefadd32ae7476c0ff6375364 100644 (file)
@@ -1970,14 +1970,25 @@ static inline int http_skip_chunk_crlf(struct http_msg *msg)
 
 /*
  * Selects a compression algorithm depending on the client request.
-*/
-
+ */
 int select_compression_request_header(struct session *s, struct buffer *req)
 {
        struct http_txn *txn = &s->txn;
        struct hdr_ctx ctx;
        struct comp_algo *comp_algo = NULL;
 
+       /* Disable compression for older user agents announcing themselves as "Mozilla/4".
+        * Note all of them are broken but they are very few and the broken ones are there.
+        * See http://zoompf.com/2012/02/lose-the-wait-http-compression for more details.
+        */
+       ctx.idx = 0;
+       if (http_find_header2("User-Agent", 10, req->p, &txn->hdr_idx, &ctx) &&
+           ctx.vlen >= 9 &&
+           memcmp(ctx.line + ctx.val, "Mozilla/4", 9) == 0) {
+               s->comp_algo = NULL;
+               return 0;
+       }
+
        ctx.idx = 0;
        /* no compression when Cache-Control: no-transform found */
        while (http_find_header2("Cache-Control", 13, req->p, &txn->hdr_idx, &ctx)) {