diff --git a/http_parser.rl b/http_parser.rl index 0d8fa50..5d27074 100644 --- a/http_parser.rl +++ b/http_parser.rl @@ -387,11 +387,11 @@ do { \ chunk_ext_val = token*; chunk_ext_name = token*; chunk_extension = ( ";" " "* chunk_ext_name ("=" chunk_ext_val)? )*; - last_chunk = "0"+ chunk_extension CRLF; - chunk_size = (xdigit* [1-9a-fA-F] xdigit*) $add_to_chunk_size; + last_chunk = "0"+ ( chunk_extension | " "+) CRLF; + chunk_size = (xdigit* [1-9a-fA-F] xdigit* ) $add_to_chunk_size; chunk_end = CRLF; chunk_body = any >skip_chunk_data; - chunk_begin = chunk_size chunk_extension CRLF; + chunk_begin = chunk_size ( chunk_extension | " "+ ) CRLF; chunk = chunk_begin chunk_body chunk_end; ChunkedBody := chunk* last_chunk trailing_headers CRLF @end_chunked_body; diff --git a/test.c b/test.c index ba8329f..0adf7e5 100644 --- a/test.c +++ b/test.c @@ -362,7 +362,34 @@ const struct message responses[] = ,.num_headers= 0 ,.headers= {} ,.body= "" -} + } + +, {.name="200 trailing space on chunked body" + ,.type= HTTP_RESPONSE + ,.raw= "HTTP/1.1 200 OK\r\n" + "Content-Type: text/plain\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "25 \r\n" + "This is the data in the first chunk\r\n" + "\r\n" + "1C\r\n" + "and this is the second one\r\n" + "\r\n" + "0 \r\n" + "\r\n" + ,.should_keep_alive= TRUE + ,.status_code= 200 + ,.num_headers= 2 + ,.headers= + { {"Content-Type", "text/plain" } + , {"Transfer-Encoding", "chunked" } + } + ,.body = + "This is the data in the first chunk\r\n" + "and this is the second one\r\n" + + } , {.name= NULL } /* sentinel */ }; @@ -653,7 +680,7 @@ test_scan (const struct message *r1, const struct message *r2, const struct mess http_parser_execute(&parser, buf3, buf3_len); - assert(! http_parser_has_error(&parser)); + assert(!http_parser_has_error(&parser)); assert(3 == num_messages);