BUG/MINOR: http-check: Don't pretend a C-L heeader is set before adding it

When a GET/HEAD/OPTIONS/DELETE healthcheck request was formatted, we claimed
there was a "content-length" header set even when there was no payload,
leading to actually send a "content-length: 0" header to the server. It was
unexpected and could be rejected by servers.

When a healthcheck request is sent we must take care to state there is a
"content-length" header when it is explicitly added.

This patch should fix the issue #2851. It must be backported as far as 2.9.
This commit is contained in:
Christopher Faulet 2025-02-03 18:36:17 +01:00
parent 0846638f7f
commit fad68cb16d

View File

@ -1569,7 +1569,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_send(struct check *check, struct tcpcheck_r
if ((istlen(vsn) == 6 && *(vsn.ptr+5) == '2') || if ((istlen(vsn) == 6 && *(vsn.ptr+5) == '2') ||
(istlen(vsn) == 8 && (*(vsn.ptr+5) > '1' || (*(vsn.ptr+5) == '1' && *(vsn.ptr+7) >= '1')))) (istlen(vsn) == 8 && (*(vsn.ptr+5) > '1' || (*(vsn.ptr+5) == '1' && *(vsn.ptr+7) >= '1'))))
slflags |= HTX_SL_F_VER_11; slflags |= HTX_SL_F_VER_11;
slflags |= (HTX_SL_F_XFER_LEN|HTX_SL_F_CLEN); slflags |= HTX_SL_F_XFER_LEN;
if (!(send->http.flags & TCPCHK_SND_HTTP_FL_BODY_FMT) && !isttest(send->http.body)) if (!(send->http.flags & TCPCHK_SND_HTTP_FL_BODY_FMT) && !isttest(send->http.body))
slflags |= HTX_SL_F_BODYLESS; slflags |= HTX_SL_F_BODYLESS;
@ -1628,6 +1628,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_send(struct check *check, struct tcpcheck_r
clen = ist((!istlen(body) ? "0" : ultoa(istlen(body)))); clen = ist((!istlen(body) ? "0" : ultoa(istlen(body))));
if (!htx_add_header(htx, ist("Content-length"), clen)) if (!htx_add_header(htx, ist("Content-length"), clen))
goto error_htx; goto error_htx;
sl->flags |= HTX_SL_F_CLEN;
} }
if (!htx_add_endof(htx, HTX_BLK_EOH) || if (!htx_add_endof(htx, HTX_BLK_EOH) ||