]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http-compression: lookup Cache-Control in the response, not the request
authorWilly Tarreau <w@1wt.eu>
Sat, 5 Jan 2013 15:20:35 +0000 (16:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 5 Jan 2013 15:31:58 +0000 (16:31 +0100)
As stated in both RFC2616 and the http-bis drafts, Cache-Control:
no-transform must be looked up in the response since we're modifying
the response. However, its presence in the request is irrelevant to
any changes in the response :

  7.2.1.6. no-transform
   The "no-transform" request directive indicates that an intermediary
   (whether or not it implements a cache) MUST NOT change the Content-
   Encoding, Content-Range or Content-Type request header fields, nor
   the request representation.

  7.2.2.9. no-transform
   The "no-transform" response directive indicates that an intermediary
   (regardless of whether it implements a cache) MUST NOT change the
   Content-Encoding, Content-Range or Content-Type response header
   fields, nor the response representation.

Note: according to the specs, we're supposed to emit the following
response header :

  Warning: 214 transformation applied

However no other product seems to do it, so the effect on user agents
is unclear.

src/proto_http.c

index aaa94766e43b6e5c76ff785b470e911dbabfd624..a2f14c9293865b5cc5a575420178d312d2f206a0 100644 (file)
@@ -1994,15 +1994,6 @@ int select_compression_request_header(struct session *s, struct buffer *req)
            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)) {
-               if (word_match(ctx.line + ctx.val, ctx.vlen, "no-transform", 12)) {
-                       s->comp_algo = NULL;
-                       return 0;
-               }
-       }
-
        /* search for the algo in the backend in priority or the frontend */
        if ((s->be->comp && (comp_algo_back = s->be->comp->algos)) || (s->fe->comp && (comp_algo_back = s->fe->comp->algos))) {
                ctx.idx = 0;
@@ -2073,6 +2064,13 @@ int select_compression_response_header(struct session *s, struct buffer *res)
        if (http_find_header2("Content-Encoding", 16, res->p, &txn->hdr_idx, &ctx))
                goto fail;
 
+       /* no compression when Cache-Control: no-transform is present in the message */
+       ctx.idx = 0;
+       while (http_find_header2("Cache-Control", 13, res->p, &txn->hdr_idx, &ctx)) {
+               if (word_match(ctx.line + ctx.val, ctx.vlen, "no-transform", 12))
+                       goto fail;
+       }
+
        comp_type = NULL;
 
        /* we don't want to compress multipart content-types, nor content-types that are