From: Finn Arne Gangstad Date: Mon, 29 Oct 2012 20:43:01 +0000 (+0100) Subject: MINOR: compression: Enable compression for IE6 w/SP2, IE7 and IE8 X-Git-Tag: v1.5-dev13~84 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cbb9a4b1284c8ec8e89e9ce0d14ae95988e92442;p=thirdparty%2Fhaproxy.git MINOR: compression: Enable compression for IE6 w/SP2, IE7 and IE8 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 ; ...) 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. --- diff --git a/src/proto_http.c b/src/proto_http.c index 61730d7531..cb24eb030c 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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;