]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: cache: respect the request cache-control header
authorWilly Tarreau <w@1wt.eu>
Fri, 22 Dec 2017 16:47:35 +0000 (17:47 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 22 Dec 2017 16:56:18 +0000 (17:56 +0100)
Till now if a client emitted a request featureing a cache-control header,
this one was not respected and a stale object could still be delievered.r
 This patch ensures that :
  - cache-control: no-cache disables retrieval from the cache but does
    not prevent the newly fetched object from being stored ;
  - cache-control: no-store can safely retrieve from the cache but prevents
    from storing any fetched object
  - cache-control: max-age/max-stale/min-fresh act like no-cache
  - pragma: no-cache acts like cache-control: no-cache.

This needs to be backported to 1.8.

src/cache.c

index 351276e4df89bac38dd1a1ab6d7e6a89b17902fe..a75c1aa8b8455614f9222f00f5d80c7070f90427 100644 (file)
@@ -670,9 +670,16 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
        struct cache_entry *res;
        struct cache *cache = (struct cache *)rule->arg.act.p[0];
 
+       check_request_for_cacheability(s, &s->req);
+       if ((s->txn->flags & (TX_CACHE_IGNORE|TX_CACHEABLE)) == TX_CACHE_IGNORE)
+               return ACT_RET_CONT;
+
        if (!sha1_hosturi(s->txn))
                return ACT_RET_CONT;
 
+       if (s->txn->flags & TX_CACHE_IGNORE)
+               return ACT_RET_CONT;
+
        shctx_lock(shctx_ptr(cache));
        res = entry_exist(cache, s->txn->cache_hash);
        if (res) {