]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: mux-h1: Don't add "transfer-encoding" if message-body is forbidden
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 30 Jan 2019 20:55:21 +0000 (21:55 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 31 Jan 2019 10:07:17 +0000 (11:07 +0100)
When a HTTP/1.1 or above response is emitted to a client, if the flag
H1_MF_XFER_LEN is set whereas H1_MF_CLEN and H1_MF_CHNK are not, the header
"transfer-encoding" is added. It is a way to make HTX chunking consistent with
H2. But we must exclude all cases where the message-body is explicitly forbidden
by the RFC:

 * for all 1XX, 204 and 304 responses
 * for any responses to HEAD requests
 * for 200 responses to CONNECT requests

For these 3 cases, the flag H1_MF_XFER_LEN is set but H1_MF_CLEN and H1_MF_CHNK
not. And the header "transfer-encoding" must not be added.

See issue #27 on github for details about the bug.

This patch must be backported in 1.9.

src/mux_h1.c

index d928cef9b4ec4330ce8ad3601ef85a71535b8c28..cce0c44a69ffdc11fada57f2ec0ed914e4d44d10 100644 (file)
@@ -1576,7 +1576,9 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun
                                        }
                                }
 
-                               if ((h1m->flags & (H1_MF_VER_11|H1_MF_RESP|H1_MF_CLEN|H1_MF_CHNK|H1_MF_XFER_LEN)) ==
+                               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)) {
                                        /* chunking needed but header not seen */
                                        if (!chunk_memcat(tmp, "transfer-encoding: chunked\r\n", 28))