]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: h1: don't consider the status for each header
authorWilly Tarreau <w@1wt.eu>
Thu, 13 Sep 2018 09:52:20 +0000 (11:52 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Sep 2018 12:30:23 +0000 (14:30 +0200)
While it was possible to consider the status before parsing response
headers, it's wrong to do it for request headers and could lead to
random behaviours due to this status matching other fields instead.
Additionnally there is little to no value in doing this for each and
every new header field. It's much better to reset the content-length
at once in the callerwhen seeing such statuses (which currently is only
the H2 mux).

No backport is needed, this is purely 1.9.

src/h1.c
src/mux_h2.c

index 47af9be32dea7914c813eb46b10414bfbd2b1f26..7a81c5099e327cebb09feed18373b2d97cf4fec3 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -1224,14 +1224,7 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
 
                        http_set_hdr(&hdr[hdr_count++], n, v);
 
-                       if (sl.st.status >= 100 && sl.st.status < 200)
-                               h1m->curr_len = h1m->body_len = 0;
-                       else if (sl.st.status == 304 || sl.st.status == 204) {
-                               /* no contents, claim c-len is present and set to zero */
-                               h1m->flags |= H1_MF_CLEN;
-                               h1m->curr_len = h1m->body_len = 0;
-                       }
-                       else if (isteqi(n, ist("transfer-encoding"))) {
+                       if (isteqi(n, ist("transfer-encoding"))) {
                                h1m->flags &= ~H1_MF_CLEN;
                                h1m->flags |= H1_MF_CHNK;
                        }
index 8d63ccde1140b26176f2e5dfde29ee1d93c97052..616038118eef8dc3ae0b5f1308413589ee5dd06f 100644 (file)
@@ -3140,6 +3140,21 @@ static size_t h2s_frt_make_resp_headers(struct h2s *h2s, const struct buffer *bu
        }
 
        h2s->status = sl.st.status;
+
+       /* certain statuses have no body or an empty one, regardless of
+        * what the headers say.
+        */
+       if (sl.st.status >= 100 && sl.st.status < 200) {
+               h1m->flags &= ~(H1_MF_CLEN | H1_MF_CHNK);
+               h1m->curr_len = h1m->body_len = 0;
+       }
+       else if (sl.st.status == 204 || sl.st.status == 304) {
+               /* no contents, claim c-len is present and set to zero */
+               h1m->flags &= ~H1_MF_CHNK;
+               h1m->flags |=  H1_MF_CLEN;
+               h1m->curr_len = h1m->body_len = 0;
+       }
+
        chunk_reset(&outbuf);
 
        while (1) {