MINOR: mux-h1: Keep custom "Content-Length: 0" header in 1xx and 204 messages
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.
This commit is contained in:
parent
1db99b09d0
commit
a6b32922fc
18
src/mux_h1.c
18
src/mux_h1.c
@ -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"))) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user