diff --git a/http_parser.c b/http_parser.c index 73b6d86..534473e 100644 --- a/http_parser.c +++ b/http_parser.c @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef MIN @@ -1849,12 +1850,11 @@ const char * http_method_str (enum http_method m) void http_parser_init (http_parser *parser, enum http_parser_type t) { + void *data = parser->data; /* preserve application data */ + memset(parser, 0, sizeof(*parser)); + parser->data = data; parser->type = t; parser->state = (t == HTTP_REQUEST ? s_start_req : (t == HTTP_RESPONSE ? s_start_res : s_start_req_or_res)); - parser->nread = 0; - parser->upgrade = 0; - parser->flags = 0; - parser->method = 0; parser->http_errno = HPE_OK; } diff --git a/test.c b/test.c index 7738fe5..ad5b008 100644 --- a/test.c +++ b/test.c @@ -1835,6 +1835,18 @@ print_error (const char *raw, size_t error_location) fprintf(stderr, "^\n\nerror location: %u\n", (unsigned int)error_location); } +void +test_preserve_data (void) +{ + char my_data[] = "application-specific data"; + http_parser parser; + parser.data = my_data; + http_parser_init(&parser, HTTP_REQUEST); + if (parser.data != my_data) { + printf("\n*** parser.data not preserved accross http_parser_init ***\n\n"); + exit(1); + } +} void test_message (const struct message *message) @@ -2295,6 +2307,9 @@ main (void) for (request_count = 0; requests[request_count].name; request_count++); for (response_count = 0; responses[response_count].name; response_count++); + //// API + test_preserve_data(); + //// OVERFLOW CONDITIONS test_header_overflow_error(HTTP_REQUEST);