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.
This commit is contained in:
Christopher Faulet 2020-10-19 18:01:38 +02:00
parent 6414cd1fc0
commit d6c48366b8
2 changed files with 16 additions and 0 deletions

View 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.

View 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);