From d5a900264f5a04c9056f0f949d29d2d14b0b0fe2 Mon Sep 17 00:00:00 2001 From: Cliff Frey Date: Mon, 1 Feb 2010 22:35:01 -0800 Subject: [PATCH] Allow newlines before HTTP requests. I have seen cases where a browser will POST data, and then send an extra CRLF before issuing the next request. --- http_parser.c | 2 ++ test.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/http_parser.c b/http_parser.c index 176ca3c..ebdc4fb 100644 --- a/http_parser.c +++ b/http_parser.c @@ -441,6 +441,8 @@ size_t http_parser_execute (http_parser *parser, case s_start_req: { + if (ch == CR || ch == LF) + break; parser->flags = 0; parser->content_length = -1; diff --git a/test.c b/test.c index a4089fa..63d4800 100644 --- a/test.c +++ b/test.c @@ -443,6 +443,27 @@ const struct message requests[] = ,.body= "" } +#define PREFIX_NEWLINE_GET 15 +/* Some clients, especially after a POST in a keep-alive connection, + * will send an extra CRLF before the next request + */ +, {.name = "newline prefix get" + ,.type= HTTP_REQUEST + ,.raw= "\r\nGET /test HTTP/1.1\r\n\r\n" + ,.should_keep_alive= TRUE + ,.message_complete_on_eof= FALSE + ,.http_major= 1 + ,.http_minor= 1 + ,.method= HTTP_GET + ,.query_string= "" + ,.fragment= "" + ,.request_path= "/test" + ,.request_url= "/test" + ,.num_headers= 0 + ,.headers= { } + ,.body= "" + } + , {.name= NULL } /* sentinel */ };