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 92eea18..1e4041b 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -1518,6 +1518,8 @@
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 @@
}
}
- 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;