Skip to content

Commit eb528db

Browse files
committed
MINOR: h1: add H1_MF_TOLOWER to decide when to turn header names to lower case
The h1 parser used to systematically turn header field names to lower case because it was designed for H2. Let's add a flag which is off by default to condition this behaviour so that when using it from an H1 parser it will not affect the message.
1 parent c2ab9f5 commit eb528db

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

include/types/h1.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ enum h1m_state {
139139
#define H1_MF_CLEN 0x00000001 // content-length present
140140
#define H1_MF_CHNK 0x00000002 // chunk present, exclusive with c-l
141141
#define H1_MF_RESP 0x00000004 // this message is the response message
142+
#define H1_MF_TOLOWER 0x00000008 // turn the header names to lower case
142143

143144

144145
/* basic HTTP/1 message state for use in parsers. The err_pos field is special,

src/h1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
10821082
/* assumes sol points to the first char */
10831083
if (likely(HTTP_IS_TOKEN(*ptr))) {
10841084
/* turn it to lower case if needed */
1085-
if (isupper((unsigned char)*ptr))
1085+
if (isupper((unsigned char)*ptr) && h1m->flags & H1_MF_TOLOWER)
10861086
*ptr = tolower(*ptr);
10871087
EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_name, http_msg_ood, state, H1_MSG_HDR_NAME);
10881088
}
@@ -1231,11 +1231,11 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
12311231
h1m->flags |= H1_MF_CLEN;
12321232
h1m->curr_len = h1m->body_len = 0;
12331233
}
1234-
else if (isteq(n, ist("transfer-encoding"))) {
1234+
else if (isteqi(n, ist("transfer-encoding"))) {
12351235
h1m->flags &= ~H1_MF_CLEN;
12361236
h1m->flags |= H1_MF_CHNK;
12371237
}
1238-
else if (isteq(n, ist("content-length")) && !(h1m->flags & H1_MF_CHNK)) {
1238+
else if (isteqi(n, ist("content-length")) && !(h1m->flags & H1_MF_CHNK)) {
12391239
h1m->flags |= H1_MF_CLEN;
12401240
strl2llrc(v.ptr, v.len, &cl);
12411241
h1m->curr_len = h1m->body_len = cl;

src/mux_h2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ static struct h2s *h2c_stream_new(struct h2c *h2c, int id)
694694
h2s->rxbuf = BUF_NULL;
695695
h1m_init_res(&h2s->h1m);
696696
h2s->h1m.err_pos = -1; // don't care about errors on the response path
697+
h2s->h1m.flags |= H1_MF_TOLOWER;
697698
h2s->by_id.key = h2s->id = id;
698699
h2c->max_id = id;
699700

@@ -3239,6 +3240,7 @@ static size_t h2s_frt_make_resp_headers(struct h2s *h2s, const struct buffer *bu
32393240
/* we'll let the caller check if it has more headers to send */
32403241
h1m_init_res(h1m);
32413242
h1m->err_pos = -1; // don't care about errors on the response path
3243+
h2s->h1m.flags |= H1_MF_TOLOWER;
32423244
goto end;
32433245
}
32443246

0 commit comments

Comments
 (0)