]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http-ana: Don't send payload for internal responses to HEAD requests
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 19 Oct 2020 16:01:38 +0000 (18:01 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 22 Oct 2020 15:13:22 +0000 (17:13 +0200)
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.

include/haproxy/htx.h
src/http_ana.c

index 5ede1a3ecb30068d87a93fbf3dc5db3a144320d8..c5e75de3a0a3ed2581bffc8e032c344d6c50dd56 100644 (file)
@@ -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 <htx>. 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.
index 870682ff9848c247d503c9b7c955090206994aa0..1dd43dcc454fbc4e63ce7c070ae75786e8988b7c 100644 (file)
@@ -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);