mirror of
https://github.com/nodejs/http-parser.git
synced 2025-10-21 07:02:06 +08:00
API Change: Return void from http_parser_execute().
This commit is contained in:
@@ -123,7 +123,7 @@ struct http_parser {
|
||||
*/
|
||||
void http_parser_init (http_parser *parser, enum http_parser_type);
|
||||
|
||||
size_t http_parser_execute (http_parser *parser, const char *data, size_t len);
|
||||
void http_parser_execute (http_parser *parser, const char *data, size_t len);
|
||||
|
||||
int http_parser_has_error (http_parser *parser);
|
||||
|
||||
|
@@ -57,7 +57,7 @@ do { \
|
||||
parser->FOR##_size += p - parser->FOR##_mark; \
|
||||
if (parser->FOR##_size > MAX_FIELD_SIZE) { \
|
||||
parser->flags |= ERROR; \
|
||||
return 0; \
|
||||
return; \
|
||||
} \
|
||||
if (parser->on_##FOR) { \
|
||||
callback_return_value = parser->on_##FOR(parser, \
|
||||
@@ -66,7 +66,7 @@ do { \
|
||||
} \
|
||||
if (callback_return_value != 0) { \
|
||||
parser->flags |= ERROR; \
|
||||
return 0; \
|
||||
return; \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
@@ -191,7 +191,7 @@ do { \
|
||||
callback_return_value = parser->on_headers_complete(parser);
|
||||
if (callback_return_value != 0) {
|
||||
parser->flags |= ERROR;
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -201,7 +201,7 @@ do { \
|
||||
callback_return_value = parser->on_message_begin(parser);
|
||||
if (callback_return_value != 0) {
|
||||
parser->flags |= ERROR;
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,7 +210,7 @@ do { \
|
||||
if (parser->content_length == -1) parser->content_length = 0;
|
||||
if (parser->content_length > INT_MAX) {
|
||||
parser->flags |= ERROR;
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
parser->content_length *= 10;
|
||||
parser->content_length += *p - '0';
|
||||
@@ -239,7 +239,7 @@ do { \
|
||||
SKIP_BODY(MIN(parser->chunk_size, REMAINING));
|
||||
if (callback_return_value != 0) {
|
||||
parser->flags |= ERROR;
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
fhold;
|
||||
@@ -285,7 +285,7 @@ do { \
|
||||
|
||||
if (callback_return_value != 0) {
|
||||
parser->flags |= ERROR;
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
fhold;
|
||||
@@ -435,7 +435,7 @@ http_parser_init (http_parser *parser, enum http_parser_type type)
|
||||
}
|
||||
|
||||
/** exec **/
|
||||
size_t
|
||||
void
|
||||
http_parser_execute (http_parser *parser, const char *buffer, size_t len)
|
||||
{
|
||||
size_t tmp; // REMOVE ME this is extremely hacky
|
||||
@@ -459,7 +459,7 @@ http_parser_execute (http_parser *parser, const char *buffer, size_t len)
|
||||
if (callback_return_value != 0) parser->flags |= ERROR;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 < parser->chunk_size && (parser->flags & EATING)) {
|
||||
@@ -467,7 +467,7 @@ http_parser_execute (http_parser *parser, const char *buffer, size_t len)
|
||||
SKIP_BODY(MIN(len, parser->chunk_size));
|
||||
if (callback_return_value != 0) {
|
||||
parser->flags |= ERROR;
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,7 +490,6 @@ http_parser_execute (http_parser *parser, const char *buffer, size_t len)
|
||||
CALLBACK(uri);
|
||||
|
||||
assert(p <= pe && "buffer overflow after parsing execute");
|
||||
return(p - buffer);
|
||||
}
|
||||
|
||||
int
|
||||
|
20
test.c
20
test.c
@@ -594,13 +594,12 @@ parse_messages (int message_count, const struct message *input_messages[])
|
||||
}
|
||||
|
||||
// Parse the stream
|
||||
size_t traversed = 0;
|
||||
parser_init(HTTP_REQUEST);
|
||||
|
||||
traversed = http_parser_execute(&parser, total, length);
|
||||
http_parser_execute(&parser, total, length);
|
||||
assert(!http_parser_has_error(&parser));
|
||||
|
||||
traversed = http_parser_execute(&parser, NULL, 0);
|
||||
http_parser_execute(&parser, NULL, 0);
|
||||
assert(!http_parser_has_error(&parser));
|
||||
|
||||
assert(num_messages == message_count);
|
||||
@@ -614,13 +613,12 @@ parse_messages (int message_count, const struct message *input_messages[])
|
||||
void
|
||||
test_message (const struct message *message)
|
||||
{
|
||||
size_t traversed = 0;
|
||||
parser_init(message->type);
|
||||
|
||||
traversed = http_parser_execute(&parser, message->raw, strlen(message->raw));
|
||||
http_parser_execute(&parser, message->raw, strlen(message->raw));
|
||||
assert(!http_parser_has_error(&parser));
|
||||
|
||||
traversed = http_parser_execute(&parser, NULL, 0);
|
||||
http_parser_execute(&parser, NULL, 0);
|
||||
assert(!http_parser_has_error(&parser));
|
||||
|
||||
assert(num_messages == 1);
|
||||
@@ -631,11 +629,10 @@ test_message (const struct message *message)
|
||||
void
|
||||
test_error (const char *buf)
|
||||
{
|
||||
size_t traversed = 0;
|
||||
parser_init(HTTP_REQUEST);
|
||||
|
||||
traversed = http_parser_execute(&parser, buf, strlen(buf));
|
||||
traversed = http_parser_execute(&parser, NULL, 0);
|
||||
http_parser_execute(&parser, buf, strlen(buf));
|
||||
http_parser_execute(&parser, NULL, 0);
|
||||
|
||||
assert(http_parser_has_error(&parser));
|
||||
}
|
||||
@@ -654,13 +651,12 @@ test_multiple3 (const struct message *r1, const struct message *r2, const struct
|
||||
strcat(total, r2->raw);
|
||||
strcat(total, r3->raw);
|
||||
|
||||
size_t traversed = 0;
|
||||
parser_init(HTTP_REQUEST);
|
||||
|
||||
traversed = http_parser_execute(&parser, total, strlen(total));
|
||||
http_parser_execute(&parser, total, strlen(total));
|
||||
assert(!http_parser_has_error(&parser) );
|
||||
|
||||
traversed = http_parser_execute(&parser, NULL, 0);
|
||||
http_parser_execute(&parser, NULL, 0);
|
||||
assert(!http_parser_has_error(&parser) );
|
||||
|
||||
assert(num_messages == 3);
|
||||
|
Reference in New Issue
Block a user