From: Christopher Faulet Date: Mon, 18 Feb 2019 09:33:16 +0000 (+0100) Subject: BUG/MINOR: mux-h1: Add "transfer-encoding" header on outgoing requests if needed X-Git-Tag: v2.0-dev1~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f890ddbe278218b259653508f3379dcded9c1a3;p=thirdparty%2Fhaproxy.git BUG/MINOR: mux-h1: Add "transfer-encoding" header on outgoing requests if needed As for outgoing response, if an HTTP/1.1 or above request is sent to a server with neither the headers "content-length" nor "transfer-encoding", it is considered as a chunked request and the header "transfer-encoding: chunked" is automatically added. Of course, it is only true for requests with a body. Concretely, it only happens for incoming HTTP/2 requests sent to an HTTP/1.1 server. This patch must be backported to 1.9. --- diff --git a/src/mux_h1.c b/src/mux_h1.c index 92eea18679..1e4041bd7e 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -1518,6 +1518,8 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun if (!htx_reqline_to_h1(sl, tmp)) goto copy; h1m->flags |= H1_MF_XFER_LEN; + if (sl->flags & HTX_SL_F_BODYLESS) + h1m->flags |= H1_MF_CLEN; h1m->state = H1_MSG_HDR_FIRST; break; @@ -1582,10 +1584,12 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun } } - if (h1s->status >= 200 && h1s->status != 204 && h1s->status != 304 && - h1s->meth != HTTP_METH_HEAD && !(h1s->meth == HTTP_METH_CONNECT && h1s->status == 200) && - (h1m->flags & (H1_MF_VER_11|H1_MF_RESP|H1_MF_CLEN|H1_MF_CHNK|H1_MF_XFER_LEN)) == - (H1_MF_VER_11|H1_MF_RESP|H1_MF_XFER_LEN)) { + if (((h1m->flags & (H1_MF_VER_11|H1_MF_RESP|H1_MF_CLEN|H1_MF_CHNK|H1_MF_XFER_LEN)) == + (H1_MF_VER_11|H1_MF_XFER_LEN)) || + (h1s->status >= 200 && h1s->status != 204 && h1s->status != 304 && + h1s->meth != HTTP_METH_HEAD && !(h1s->meth == HTTP_METH_CONNECT && h1s->status == 200) && + (h1m->flags & (H1_MF_VER_11|H1_MF_RESP|H1_MF_CLEN|H1_MF_CHNK|H1_MF_XFER_LEN)) == + (H1_MF_VER_11|H1_MF_RESP|H1_MF_XFER_LEN))) { /* chunking needed but header not seen */ if (!chunk_memcat(tmp, "transfer-encoding: chunked\r\n", 28)) goto copy;