]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mux-h1: Only skip invalid C-L headers on output
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 27 Mar 2019 14:44:56 +0000 (15:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 28 Mar 2019 09:00:36 +0000 (10:00 +0100)
When an HTTP request with an empty body is received, the flag HTX_SL_F_BODYLESS
is set on the HTX start-line block. It is true if the header content-length is
explicitly set to 0 or if it is omitted for a non chunked request.

On the server side, when the request is reformatted, because HTX_SL_F_BODYLESS
is set, the flag H1_MF_CLEN is added on the request parser. It is done to not
add an header transfer-encoding on bodyless requests. But if an header
content-length is explicitly set to 0, when it is parsed, because H1_MF_CLEN is
set, the function h1_parse_cont_len_header() returns 0, meaning the header can
be dropped. So in such case, a request without any header content-length is sent
to the server.

Some servers seems to reject empty POST requests with an error 411 when there is
no header content-length. So to fix this issue, on the output side, only headers
with an invalid content length are skipped, ie only when the function
h1_parse_cont_len_header() returns a negative value.

This patch must be backported to 1.9.

src/mux_h1.c

index 65e99153d00714a5cf1f5e160c081c0143eece26..2b4e1cf09af1985ac9baa551f997e24be6d18008 100644 (file)
@@ -1557,7 +1557,8 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun
                                if (isteqi(n, ist("transfer-encoding")))
                                        h1_parse_xfer_enc_header(h1m, v);
                                else if (isteqi(n, ist("content-length"))) {
-                                       if (h1_parse_cont_len_header(h1m, &v) <= 0)
+                                       /* Only skip C-L header with invalid value. */
+                                       if (h1_parse_cont_len_header(h1m, &v) < 0)
                                                goto skip_hdr;
                                }
                                else if (isteqi(n, ist("connection"))) {