From: Christopher Faulet Date: Mon, 19 Oct 2020 16:01:38 +0000 (+0200) Subject: BUG/MINOR: http-ana: Don't send payload for internal responses to HEAD requests X-Git-Tag: v2.3-dev8~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6c48366b81e4f95676b038db32d23cdc541735e;p=thirdparty%2Fhaproxy.git BUG/MINOR: http-ana: Don't send payload for internal responses to HEAD requests When an internal response is returned to a client, the message payload must be skipped if it is a reply to a HEAD request. The payload is removed from the HTX message just before the message forwarding. This bugs has been around for a long time. It was already there in the pre-HTX versions. In legacy HTTP mode, internal errors are not parsed. So this bug cannot be easily fixed. Thus, this patch should only be backported in all HTX versions, as far as 2.0. However, the code has significantly changed in the 2.2. Thus in the 2.1 and 2.0, the patch must be entirely reworked. --- diff --git a/include/haproxy/htx.h b/include/haproxy/htx.h index 5ede1a3ecb..c5e75de3a0 100644 --- a/include/haproxy/htx.h +++ b/include/haproxy/htx.h @@ -610,6 +610,19 @@ static inline int htx_copy_msg(struct htx *htx, const struct buffer *msg) return htx_append_msg(htx, htxbuf(msg)); } +static inline void htx_skip_msg_payload(struct htx *htx) +{ + struct htx_blk *blk = htx_get_first_blk(htx); + + while (blk) { + enum htx_blk_type type = htx_get_blk_type(blk); + + blk = ((type > HTX_BLK_EOH && type < HTX_BLK_EOM) + ? htx_remove_blk(htx, blk) + : htx_get_next_blk(htx, blk)); + } +} + /* Returns the number of used blocks in the HTX message . Note that it is * illegal to call this function with htx == NULL. Note also blocks of type * HTX_BLK_UNUSED are part of used blocks. diff --git a/src/http_ana.c b/src/http_ana.c index 870682ff98..1dd43dcc45 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -4575,6 +4575,9 @@ int http_forward_proxy_resp(struct stream *s, int final) if (!http_eval_after_res_rules(s)) return 0; + if (s->txn->meth == HTTP_METH_HEAD) + htx_skip_msg_payload(htx); + channel_auto_read(req); channel_abort(req); channel_auto_close(req);