diff --git a/src/connections.c b/src/connections.c index 609e71ad..02764700 100644 --- a/src/connections.c +++ b/src/connections.c @@ -813,23 +813,6 @@ static chunk * connection_read_header_more(connection *con, chunkqueue *cq, chun : NULL; } -__attribute_hot__ -static uint32_t connection_read_header_hoff(const char *n, const uint32_t clen, unsigned short hoff[8192]) { - uint32_t hlen = 0; - for (const char *b; (n = memchr((b = n),'\n',clen-hlen)); ++n) { - uint32_t x = (uint32_t)(n - b + 1); - hlen += x; - if (x <= 2 && (x == 1 || n[-1] == '\r')) { - hoff[hoff[0]+1] = hlen; - return hlen; - } - if (++hoff[0] >= /*sizeof(hoff)/sizeof(hoff[0])-1*/ 8192-1) break; - hoff[hoff[0]] = hlen; - } - return 0; -} - - static void http_request_headers_process (request_st * const r, char * const hdrs, unsigned short * const hoff, const int scheme_port) { @@ -904,8 +887,7 @@ static int connection_handle_read_state(connection * const con) { hoff[1] = (unsigned short)c->offset; /* base offset for all lines */ /*hoff[2] = ...;*/ /* offset from base for 2nd line */ - header_len = - connection_read_header_hoff(c->mem->ptr + c->offset, clen, hoff); + header_len = http_header_parse_hoff(c->mem->ptr + c->offset,clen,hoff); /* casting to (unsigned short) might truncate, and the hoff[] * addition might overflow, but max_request_field_size is USHRT_MAX, diff --git a/src/http_header.c b/src/http_header.c index 9a52a1b6..bbc623ac 100644 --- a/src/http_header.c +++ b/src/http_header.c @@ -241,3 +241,21 @@ void http_header_env_append(request_st * const r, const char *k, uint32_t klen, if (0 == vlen) return; http_header_token_append(vb, v, vlen); } + + +uint32_t +http_header_parse_hoff (const char *n, const uint32_t clen, unsigned short hoff[8192]) +{ + uint32_t hlen = 0; + for (const char *b; (n = memchr((b = n),'\n',clen-hlen)); ++n) { + uint32_t x = (uint32_t)(n - b + 1); + hlen += x; + if (x <= 2 && (x == 1 || n[-1] == '\r')) { + hoff[hoff[0]+1] = hlen; + return hlen; + } + if (++hoff[0] >= /*sizeof(hoff)/sizeof(hoff[0])-1*/ 8192-1) break; + hoff[hoff[0]] = hlen; + } + return 0; +} diff --git a/src/http_header.h b/src/http_header.h index b302a23c..9fa652b5 100644 --- a/src/http_header.h +++ b/src/http_header.h @@ -70,4 +70,7 @@ buffer * http_header_env_get(const request_st *r, const char *k, uint32_t klen); void http_header_env_set(request_st *r, const char *k, uint32_t klen, const char *v, uint32_t vlen); void http_header_env_append(request_st *r, const char *k, uint32_t klen, const char *v, uint32_t vlen); +__attribute_hot__ +uint32_t http_header_parse_hoff (const char *n, const uint32_t clen, unsigned short hoff[8192]); + #endif