]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h1: Keep custom "Content-Length: 0" header in 1xx and 204 messages
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 15 Apr 2025 17:04:42 +0000 (19:04 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 22 Apr 2025 14:14:47 +0000 (16:14 +0200)
Thanks to the commit "MINOR: mux-h1: Don't remove custom "Content-Length: 0"
header in 1xx and 204 messages", we are now sure that 1xx and 204 responses
were sanitized during the parsing. So, if one of these headers are found in
such responses when sent to the client, it means it was added by hand, via a
"set-header" action for instance. In this context, we are able to make an
exception for the "Content-Length: 0" header, and only this one with this
value, to not break leagacy applications.

So now, a user can force the "Content-Length: 0" header to appear in 1xx and
204 responses by adding the right action in hist configuration.
"Transfer-Encoding" headers are still dropped as "Content-Length" headers
with another value than 0. Note, that in practice, only 101 and 204 are
concerned because other 1xx message are not subject to HTTP analysis.

This patch should fix the issue #2888. There is no reason to backport
it. But if we do so, the patch above must be backported too.

src/mux_h1.c

index 17dd746522cc33ee8fac651ab507732c7297c3eb..864d3cce2379aac1bc583409a332f617a1815fef 100644 (file)
@@ -2596,17 +2596,21 @@ static size_t h1_make_headers(struct h1s *h1s, struct h1m *h1m, struct htx *htx,
                                h1s->flags |= H1S_F_HAVE_CHNK;
                         }
                        else if (isteq(n, ist("content-length"))) {
-                               if ((h1m->flags & H1_MF_RESP) && (h1s->status < 200 || h1s->status == 204))
-                                       goto nextblk;
+                               unsigned long long body_len = h1m->body_len;
+
+                               /* Report error for invalid content-length.
+                                * Skip custom content-length headers except "content-length: 0"
+                                * for 1xx and 204 messages.
+                                */
+                               if (http_parse_cont_len_header(&v, &body_len, (h1s->flags & H1S_F_HAVE_CLEN)) < 0)
+                                       goto error;
+                               if (!body_len && (h1m->flags & H1_MF_RESP) && (h1s->status < 200 || h1s->status == 204))
+                                       h1m->flags |= H1_MF_CLEN;
                                if (!(h1m->flags & H1_MF_CLEN))
                                        goto nextblk;
-                               if (!(h1s->flags & H1S_F_HAVE_CLEN))
-                                       h1m->flags &= ~H1_MF_CLEN;
-                               /* Only skip C-L header with invalid value. */
-                               if (h1_parse_cont_len_header(h1m, &v) < 0)
-                                       goto error;
                                if (h1s->flags & H1S_F_HAVE_CLEN)
                                        goto nextblk;
+                               h1m->curr_len = h1m->body_len = body_len;
                                h1s->flags |= H1S_F_HAVE_CLEN;
                        }
                        else if (isteq(n, ist("connection"))) {