From f0dd03745647f91bb4adba1412e51a828cd112bc Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 25 Feb 2019 11:08:34 +0100 Subject: [PATCH] BUG/MINOR: cache/htx: Return only the headers of cached objects to HEAD requests The body of a cached object must not be sent in response to a HEAD request. This works for the legacy HTTP because the parsing is performed by HTTP analyzers _AND_ because the connection is closed at the end of the transaction. So the body is ignored. But the applet send it. For the HTX, the applet must skip the body explicitly. This patch must be backported to 1.9. --- src/cache.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cache.c b/src/cache.c index f1ad3c7e2..fddff72c3 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1023,7 +1023,11 @@ static void htx_cache_io_handler(struct appctx *appctx) goto error; total += ret; - if (cache_ptr->data_len) + if (si_strm(si)->txn->meth == HTTP_METH_HEAD) { + /* Skip response body for HEAD requests */ + appctx->st0 = HTX_CACHE_EOM; + } + else if (cache_ptr->data_len) appctx->st0 = HTX_CACHE_DATA; else if (first->len > sizeof(*cache_ptr) + appctx->ctx.cache.sent) { /* Headers have benn sent (hrds_len) and there is no data