]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compression: Enable compression for IE6 w/SP2, IE7 and IE8
authorFinn Arne Gangstad <finnag@gmail.com>
Mon, 29 Oct 2012 20:43:01 +0000 (21:43 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 29 Oct 2012 21:03:14 +0000 (22:03 +0100)
Some old browsers that have a user-agent starting with "Mozilla/4" do
not support compressison correctly, so disable compression for those.

Internet explorer 6 after Windows XP service pack 2, IE 7, and IE 8,
do however support compression and still have a user agent starting
with Mozilla/4, so we try to enable compression for those.

MSIE has a user-agent on this form:
Mozilla/4.0 (compatible; MSIE <version>; ...)

98% of MSIE 6 SP2 user agents start with
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1
The remaining 2% have additional flags before "SV1".

This simplified matching looking for MSIE at exactly position 25
and SV1 at exacly position 51 gives a few false negatives, so sometimes
a compression opportunity is lost.

A test against 3 hours of traffic to around 3000 news sites worldwide
gives less than 0.007% (70ppm) missed compression opportunities.

src/proto_http.c

index 61730d753167eb85982d773fe2fc320a9a705ab0..cb24eb030cfb9749d4e882e9bd4f40933f566c84 100644 (file)
@@ -1974,16 +1974,21 @@ int select_compression_request_header(struct session *s, struct buffer *req)
        struct comp_algo *comp_algo = NULL;
        struct comp_algo *comp_algo_back = 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.
+       /* Disable compression for older user agents announcing themselves as "Mozilla/4"
+        * unless they are known good (MSIE 6 with XP SP2, or MSIE 7 and later).
         * 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;
+           memcmp(ctx.line + ctx.val, "Mozilla/4", 9) == 0 &&
+           (ctx.vlen < 31 ||
+            memcmp(ctx.line + ctx.val + 25, "MSIE ", 5) != 0 ||
+            ctx.line[ctx.val + 30] < '6' ||
+            (ctx.line[ctx.val + 30] == '6' &&
+             (ctx.vlen < 54 || memcmp(ctx.line + 51, "SV1", 3) != 0)))) {
+           s->comp_algo = NULL;
+           return 0;
        }
 
        ctx.idx = 0;