From 594485c2e1b59d2e668a191bea49bdd5ab47c0d9 Mon Sep 17 00:00:00 2001 From: tomika Date: Sat, 24 Mar 2012 10:17:24 +0100 Subject: [PATCH 1/3] "status complete" callback added to support Simple-Response handling in HTTP version <= 1.0 --- http_parser.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/http_parser.h b/http_parser.h index 8ed41803..4405170e 100644 --- a/http_parser.h +++ b/http_parser.h @@ -150,6 +150,7 @@ enum flags \ /* Callback-related errors */ \ XX(CB_message_begin, "the on_message_begin callback failed") \ + XX(CB_status_complete, "the on_status_complete callback failed") \ XX(CB_url, "the on_url callback failed") \ XX(CB_header_field, "the on_header_field callback failed") \ XX(CB_header_value, "the on_header_value callback failed") \ @@ -241,6 +242,7 @@ struct http_parser { struct http_parser_settings { http_cb on_message_begin; http_data_cb on_url; + http_cb on_status_complete; http_data_cb on_header_field; http_data_cb on_header_value; http_cb on_headers_complete; From 1d9c1bf1c70d8e6b3cb098acc39799fe292d6f5c Mon Sep 17 00:00:00 2001 From: tomika Date: Sat, 24 Mar 2012 10:18:23 +0100 Subject: [PATCH 2/3] "status complete" callback added to support Simple-Response handling in HTTP version <= 1.0 --- http_parser.c | 1 + 1 file changed, 1 insertion(+) diff --git a/http_parser.c b/http_parser.c index acd41307..cf526352 100644 --- a/http_parser.c +++ b/http_parser.c @@ -868,6 +868,7 @@ size_t http_parser_execute (http_parser *parser, case s_res_line_almost_done: STRICT_CHECK(ch != LF); parser->state = s_header_field_start; + CALLBACK_NOTIFY(status_complete); break; case s_start_req: From f1baae51817288a864b4bca70be8742f841a7ffd Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Sat, 15 Dec 2012 11:50:24 -0500 Subject: [PATCH 3/3] Add tests for @tomika's patch --- http_parser.c | 2 +- test.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/http_parser.c b/http_parser.c index 367340d5..ed3a9232 100644 --- a/http_parser.c +++ b/http_parser.c @@ -866,7 +866,7 @@ size_t http_parser_execute (http_parser *parser, case s_res_line_almost_done: STRICT_CHECK(ch != LF); parser->state = s_header_field_start; - CALLBACK_NOTIFY(status_complete); + CALLBACK_NOTIFY(status_complete); break; case s_start_req: diff --git a/test.c b/test.c index b6c2acbc..83723b7f 100644 --- a/test.c +++ b/test.c @@ -1491,6 +1491,13 @@ request_url_cb (http_parser *p, const char *buf, size_t len) return 0; } +int +status_complete_cb (http_parser *p) { + assert(p == parser); + p->data++; + return 0; +} + int header_field_cb (http_parser *p, const char *buf, size_t len) { @@ -3089,6 +3096,20 @@ create_large_chunked_message (int body_size_in_kb, const char* headers) return buf; } +void +test_status_complete (void) +{ + parser_init(HTTP_RESPONSE); + parser->data = 0; + http_parser_settings settings = settings_null; + settings.on_status_complete = status_complete_cb; + + char *response = "don't mind me, just a simple response"; + http_parser_execute(parser, &settings, response, strlen(response)); + assert(parser->data == (void*)0); // the status_complete callback was never called + assert(parser->http_errno == HPE_INVALID_CONSTANT); // the errno for an invalid status line +} + /* Verify that we can pause parsing at any of the bytes in the * message and still get the result that we're expecting. */ void @@ -3396,6 +3417,8 @@ main (void) , &requests[CONNECT_REQUEST] ); + test_status_complete(); + puts("requests okay"); return 0;