]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http: do not ignore cache-control: public
authorWilly Tarreau <w@1wt.eu>
Thu, 21 Dec 2017 15:08:09 +0000 (16:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 22 Dec 2017 13:43:26 +0000 (14:43 +0100)
In check_response_for_cacheability(), we don't check the
cache-control flags if the response is already supposed not to be
cacheable. This was introduced very early when cache-control:public
was not checked, and it basically results in this last one not being
able to properly mark the response as cacheable if it uses a status
code which is non-cacheable by default. Till now the impact is very
limited as it doesn't check that cookies set on non-default status
codes are not cacheable, and it prevents the cache from caching such
responses.

Let's fix this by doing two things :
  - remove the test for !TX_CACHEABLE in the aforementionned function
  - however take care of 1xx status codes here (which used to be
    implicitly dealt with by the test above) and remove the explicit
    check for 101 in the caller

This fix must be backported to 1.8.

src/proto_http.c

index afeb96ee52d4ac47743b4bd2c31b660f6b8366e3..42e253aeb997d29bb0802d99c7c9ac06fd88dfd3 100644 (file)
@@ -5833,7 +5833,7 @@ int http_process_res_common(struct stream *s, struct channel *rep, int an_bit, s
        /*
         * Check for cache-control or pragma headers if required.
         */
-       if (((s->be->options & PR_O_CHK_CACHE) || (s->be->ck_opts & PR_CK_NOC)) && txn->status != 101)
+       if ((s->be->options & PR_O_CHK_CACHE) || (s->be->ck_opts & PR_CK_NOC))
                check_response_for_cacheability(s, rep);
 
        /*
@@ -7690,8 +7690,11 @@ void check_response_for_cacheability(struct stream *s, struct channel *rtr)
        char *cur_ptr, *cur_end, *cur_next;
        int cur_idx;
 
-       if (!(txn->flags & TX_CACHEABLE))
+       if (txn->status < 200) {
+               /* do not try to cache interim responses! */
+               txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK;
                return;
+       }
 
        /* Iterate through the headers.
         * we start with the start line.