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 5ede1a3..c5e75de 100644
--- a/include/haproxy/htx.h
+++ b/include/haproxy/htx.h
@@ -610,6 +610,19 @@
 	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.
diff --git a/src/http_ana.c b/src/http_ana.c
index 870682f..1dd43dc 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -4575,6 +4575,9 @@
 		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);