Merge pull request #82 from ivosh/master

http_parser_init does not clear status_code
v0.10
Ben Noordhuis 13 years ago
commit e4c13a8784

@ -26,6 +26,7 @@
#include <stddef.h> #include <stddef.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#ifndef MIN #ifndef MIN
@ -1849,12 +1850,11 @@ const char * http_method_str (enum http_method m)
void void
http_parser_init (http_parser *parser, enum http_parser_type t) 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->type = t;
parser->state = (t == HTTP_REQUEST ? s_start_req : (t == HTTP_RESPONSE ? s_start_res : s_start_req_or_res)); 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; parser->http_errno = HPE_OK;
} }

@ -1835,6 +1835,18 @@ print_error (const char *raw, size_t error_location)
fprintf(stderr, "^\n\nerror location: %u\n", (unsigned int)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 void
test_message (const struct message *message) test_message (const struct message *message)
@ -2295,6 +2307,9 @@ main (void)
for (request_count = 0; requests[request_count].name; request_count++); for (request_count = 0; requests[request_count].name; request_count++);
for (response_count = 0; responses[response_count].name; response_count++); for (response_count = 0; responses[response_count].name; response_count++);
//// API
test_preserve_data();
//// OVERFLOW CONDITIONS //// OVERFLOW CONDITIONS
test_header_overflow_error(HTTP_REQUEST); test_header_overflow_error(HTTP_REQUEST);

Loading…
Cancel
Save