]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h1: make the H1 headers block parser able to parse headers only
authorWilly Tarreau <w@1wt.eu>
Fri, 4 Jan 2019 09:48:03 +0000 (10:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 4 Jan 2019 09:48:03 +0000 (10:48 +0100)
Currently the H1 headers parser works for either a request or a response
because it starts from the start line. It is also able to resume its
processing when it was interrupted, but in this case it doesn't update
the list.

Make it support a new flag, H1_MF_HDRS_ONLY so that the caller can
indicate it's only interested in the headers list and not the start
line. This will be convenient to parse H1 trailers.

include/common/h1.h
src/h1.c

index b77eb32ca4febc2cff90d9f163ea10f5a9ffb6b0..f0f2039310c3a9b5ce4635773a8e95a695135d26 100644 (file)
@@ -92,6 +92,7 @@ enum h1m_state {
 #define H1_MF_XFER_LEN          0x00000100 // message xfer size can be determined
 #define H1_MF_XFER_ENC          0x00000200 // transfer-encoding is present
 #define H1_MF_NO_PHDR           0x00000400 // don't add pseudo-headers in the header list
+#define H1_MF_HDRS_ONLY         0x00000800 // parse headers only
 
 /* Note: for a connection to be persistent, we need this for the request :
  *   - one of CLEN or CHNK
index 37a144269742e5059f5ef4ec5262cb3281ac4212..f9e8c9c0ffb327ad72c3206e07261b572e2cb1ff 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -229,7 +229,9 @@ void h1_parse_connection_header(struct h1m *h1m, struct ist value)
  * checked. In case of an unparsable response message, a negative value will be
  * returned with h1m->err_pos and h1m->err_state matching the location and
  * state where the error was met. Leading blank likes are tolerated but not
- * recommended.
+ * recommended. If flag H1_MF_HDRS_ONLY is set in h1m->flags, only headers are
+ * parsed and the start line is skipped. It is not required to set h1m->state
+ * nor h1m->next in this case.
  *
  * This function returns :
  *    -1 in case of error. In this case, h1m->err_state is filled (if h1m is
@@ -266,12 +268,17 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
        sl.st.status = 0;
        skip_update = restarting = 0;
 
+       if (h1m->flags & H1_MF_HDRS_ONLY) {
+               state = H1_MSG_HDR_FIRST;
+               h1m->next = 0;
+       }
+       else if (h1m->state == H1_MSG_RQBEFORE || h1m->state == H1_MSG_RPBEFORE)
+               state = h1m->state;
+       else
+               restarting = 1;
+
        ptr   = start + h1m->next;
        end   = stop;
-       state = h1m->state;
-
-       if (state != H1_MSG_RQBEFORE && state != H1_MSG_RPBEFORE)
-               restarting = 1;
 
        if (unlikely(ptr >= end))
                goto http_msg_ood;