From 0d4ce93fcf9bd1f350c95f5a1bbe403bce57c680 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 16 Oct 2019 09:09:04 +0200 Subject: [PATCH] BUG/MINOR: http-htx: Properly set htx flags on error files to support keep-alive When an error file was loaded, the flag HTX_SL_F_XFER_LEN was never set on the HTX start line because of a bug. During the headers parsing, the flag H1_MF_XFER_LEN is never set on the h1m. But it was the condition to set HTX_SL_F_XFER_LEN on the HTX start-line. Instead, we must only rely on the flags H1_MF_CLEN or H1_MF_CHNK. Because of this bug, it was impossible to keep a connection alive for a response generated by HAProxy. Now the flag HTX_SL_F_XFER_LEN is set when an error file have a content length (chunked responses are unsupported at this stage) and the connection may be kept alive if there is no connection header specified to explicitly close it. This patch must be backported to 2.0 and 1.9. --- src/http_htx.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/http_htx.c b/src/http_htx.c index dbe9f67c7..7489f6288 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -771,16 +771,13 @@ int http_str_to_htx(struct buffer *buf, struct ist raw) flags |= HTX_SL_F_VER_11; if (h1m.flags & H1_MF_XFER_ENC) flags |= HTX_SL_F_XFER_ENC; - if (h1m.flags & H1_MF_XFER_LEN) { - flags |= HTX_SL_F_XFER_LEN; - if (h1m.flags & H1_MF_CHNK) - goto error; /* Unsupported because there is no body parsing */ - else if (h1m.flags & H1_MF_CLEN) { - flags |= HTX_SL_F_CLEN; - if (h1m.body_len == 0) - flags |= HTX_SL_F_BODYLESS; - } + if (h1m.flags & H1_MF_CLEN) { + flags |= (HTX_SL_F_XFER_LEN|HTX_SL_F_CLEN); + if (h1m.body_len == 0) + flags |= HTX_SL_F_BODYLESS; } + if (h1m.flags & H1_MF_CHNK) + goto error; /* Unsupported because there is no body parsing */ htx = htx_from_buf(buf); sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, h1sl.st.v, h1sl.st.c, h1sl.st.r);