Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit da91852

Browse files
committed
Eat CRLF between requests, even on connection:close.
Fixes #47.
1 parent b47c44d commit da91852

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

http_parser.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ size_t http_parser_execute (http_parser *parser,
433433
/* this state is used after a 'Connection: close' message
434434
* the parser will error out if it reads another message
435435
*/
436+
if (ch == CR || ch == LF)
437+
break;
438+
436439
SET_ERRNO(HPE_CLOSED_CONNECTION);
437440
goto error;
438441

test.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,56 @@ const struct message requests[] =
680680
,.body= ""
681681
}
682682

683+
/* see https://github.com/ry/http-parser/issues/47 */
684+
#define EAT_TRAILING_CRLF_NO_CONNECTION_CLOSE 28
685+
, {.name = "eat CRLF between requests, no \"Connection: close\" header"
686+
,.raw= "POST / HTTP/1.1\r\n"
687+
"Host: www.example.com\r\n"
688+
"Content-Type: application/x-www-form-urlencoded\r\n"
689+
"Content-Length: 4\r\n"
690+
"\r\n"
691+
"q=42\r\n" /* note the trailing CRLF */
692+
,.should_keep_alive= TRUE
693+
,.message_complete_on_eof= FALSE
694+
,.http_major= 1
695+
,.http_minor= 1
696+
,.method= HTTP_POST
697+
,.request_url= "/"
698+
,.num_headers= 3
699+
,.upgrade= 0
700+
,.headers= { { "Host", "www.example.com" }
701+
, { "Content-Type", "application/x-www-form-urlencoded" }
702+
, { "Content-Length", "4" }
703+
}
704+
,.body= "q=42"
705+
}
706+
707+
/* see https://github.com/ry/http-parser/issues/47 */
708+
#define EAT_TRAILING_CRLF_WITH_CONNECTION_CLOSE 29
709+
, {.name = "eat CRLF between requests even if \"Connection: close\" is set"
710+
,.raw= "POST / HTTP/1.1\r\n"
711+
"Host: www.example.com\r\n"
712+
"Content-Type: application/x-www-form-urlencoded\r\n"
713+
"Content-Length: 4\r\n"
714+
"Connection: close\r\n"
715+
"\r\n"
716+
"q=42\r\n" /* note the trailing CRLF */
717+
,.should_keep_alive= FALSE
718+
,.message_complete_on_eof= FALSE /* input buffer isn't empty when on_message_complete is called */
719+
,.http_major= 1
720+
,.http_minor= 1
721+
,.method= HTTP_POST
722+
,.request_url= "/"
723+
,.num_headers= 4
724+
,.upgrade= 0
725+
,.headers= { { "Host", "www.example.com" }
726+
, { "Content-Type", "application/x-www-form-urlencoded" }
727+
, { "Content-Length", "4" }
728+
, { "Connection", "close" }
729+
}
730+
,.body= "q=42"
731+
}
732+
683733
, {.name= NULL } /* sentinel */
684734
};
685735

0 commit comments

Comments
 (0)