Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,11 @@ size_t http_parser_execute (http_parser *parser,
parser->header_state = h_content_length_num;
break;

/* when obsolete line folding is encountered for content length
* continue to the s_header_value state */
case h_content_length_ws:
break;

case h_connection:
/* looking for 'Connection: keep-alive' */
if (c == 'k') {
Expand Down Expand Up @@ -1677,6 +1682,10 @@ size_t http_parser_execute (http_parser *parser,
case s_header_value_lws:
{
if (ch == ' ' || ch == '\t') {
if (parser->header_state == h_content_length_num) {
/* treat obsolete line folding as space */
parser->header_state = h_content_length_ws;
}
UPDATE_STATE(s_header_value_start);
REEXECUTE();
}
Expand Down
14 changes: 14 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4203,6 +4203,20 @@ main (void)
HPE_INVALID_CONTENT_LENGTH,
HTTP_REQUEST);

test_simple_type(
"POST / HTTP/1.1\r\n"
"Content-Length: 42\r\n"
" Hello world!\r\n",
HPE_INVALID_CONTENT_LENGTH,
HTTP_REQUEST);

test_simple_type(
"POST / HTTP/1.1\r\n"
"Content-Length: 42\r\n"
" \r\n",
HPE_OK,
HTTP_REQUEST);

//// RESPONSES

test_simple_type("HTP/1.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE);
Expand Down