From: Baptiste Assmann Date: Wed, 7 Aug 2019 10:24:36 +0000 (+0200) Subject: MINOR: cache: allow caching of OPTIONS request X-Git-Tag: v2.1-dev2~223 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1263540fe824c74bc3c668fec3476b880d65b27c;p=thirdparty%2Fhaproxy.git MINOR: cache: allow caching of OPTIONS request Allow HAProxy to cache responses to OPTIONS HTTP requests. This is useful in the use case of "Cross-Origin Resource Sharing" (cors) to cache CORS responses from API servers. Since HAProxy does not support Vary header for now, this would be only useful for "access-control-allow-origin: *" use case. --- diff --git a/src/cache.c b/src/cache.c index 5b4062384a..001532651d 100644 --- a/src/cache.c +++ b/src/cache.c @@ -560,8 +560,8 @@ enum act_return http_action_store_cache(struct act_rule *rule, struct proxy *px, if (!(txn->req.flags & HTTP_MSGF_VER_11)) goto out; - /* cache only GET method */ - if (txn->meth != HTTP_METH_GET) + /* cache only GET or OPTIONS method */ + if (txn->meth != HTTP_METH_GET && txn->meth != HTTP_METH_OPTIONS) goto out; /* cache key was not computed */ @@ -1058,6 +1058,9 @@ int sha1_hosturi(struct stream *s) ctx.blk = NULL; switch (txn->meth) { + case HTTP_METH_OPTIONS: + chunk_memcat(trash, "OPTIONS", 7); + break; case HTTP_METH_HEAD: case HTTP_METH_GET: chunk_memcat(trash, "GET", 3); @@ -1093,10 +1096,10 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p struct cache_flt_conf *cconf = rule->arg.act.p[0]; struct cache *cache = cconf->c.cache; - /* Ignore cache for HTTP/1.0 requests and for requests other than GET - * and HEAD */ + /* Ignore cache for HTTP/1.0 requests and for requests other than GET, + * HEAD and OPTIONS */ if (!(txn->req.flags & HTTP_MSGF_VER_11) || - (txn->meth != HTTP_METH_GET && txn->meth != HTTP_METH_HEAD)) + (txn->meth != HTTP_METH_GET && txn->meth != HTTP_METH_HEAD && txn->meth != HTTP_METH_OPTIONS)) txn->flags |= TX_CACHE_IGNORE; http_check_request_for_cacheability(s, &s->req);