MINOR: h1: make the H1 headers block parser able to parse headers only
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.
This commit is contained in:
parent
7eeb10a5b5
commit
0f8fb6b7f9
|
@ -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
|
||||
|
|
17
src/h1.c
17
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;
|
||||
|
|
Loading…
Reference in New Issue