]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mux-h1: Skip trailers for non-chunked outgoing messages
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 27 Jun 2019 15:40:14 +0000 (17:40 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 1 Jul 2019 14:24:01 +0000 (16:24 +0200)
Unlike H1, H2 messages may contains trailers while the header "Content-Length"
is set. Indeed, because of the framed structure of HTTP/2, it is no longer
necessary to use the chunked transfer encoding. So Trailing HEADERS frames,
after all DATA frames, may be added on messages with an explicit content length.

But in H1, it is impossible to have trailers on non-chunked messages. So when
outgoing messages are formatted by the H1 multiplexer, if the message is not
chunked, all trailers must be dropped.

This patch must be backported to 2.0 and 1.9. However, the patch will have to be
adapted for the 1.9.

src/mux_h1.c

index e497e6f68d6ca391b3bcca1aa256e33783d66a9b..e7d769b429190a135e484d21bc938674aebfdc3d 100644 (file)
@@ -1696,7 +1696,9 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun
                                        goto done;
                                }
                                else if (type == HTX_BLK_EOT || type == HTX_BLK_TLR) {
-                                       if (!chunk_memcat(&tmp, "0\r\n", 3))
+                                       /* If the message is not chunked, never
+                                        * add the last chunk. */
+                                       if ((h1m->flags & H1_MF_CHNK) && !chunk_memcat(&tmp, "0\r\n", 3))
                                                goto copy;
                                        goto trailers;
                                }
@@ -1715,6 +1717,11 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun
                                        goto error;
                          trailers:
                                h1m->state = H1_MSG_TRAILERS;
+                               /* If the message is not chunked, ignore
+                                * trailers. It may happen with H2 messages. */
+                               if (!(h1m->flags & H1_MF_CHNK))
+                                       break;
+
                                if (type == HTX_BLK_EOT) {
                                        if (!chunk_memcat(&tmp, "\r\n", 2))
                                                goto copy;