New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "int http_body_is_final(const http_parser *parser)" method. #124

Closed
wants to merge 1 commit into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+37 −3
Diff settings

Always

Just for now

Add "int http_body_is_final(const http_parser *parser)" method.

It's useful to check if the current chunk is the last one.
  • Loading branch information...
bog-dan-ro committed Aug 31, 2012
commit 946ddccf28fc39457b8e72a1f9da2cc30f92a79e
View
@@ -107,7 +107,7 @@ do { \
FOR##_mark = NULL; \
} \
} while (0)
/* Run the data callback FOR and consume the current byte */
#define CALLBACK_DATA(FOR) \
CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1)
@@ -2175,3 +2175,8 @@ http_parser_pause(http_parser *parser, int paused) {
assert(0 && "Attempting to pause parser in error state");
}
}
int
http_body_is_final(const struct http_parser *parser) {
return parser->state ==s_message_done;
}
View
@@ -141,7 +141,7 @@ enum flags
/* Map for errno-related constants
*
*
* The provided argument should be a macro that takes 2 arguments.
*/
#define HTTP_ERRNO_MAP(XX) \
@@ -313,6 +313,9 @@ int http_parser_parse_url(const char *buf, size_t buflen,
/* Pause or un-pause the parser; a nonzero value pauses */
void http_parser_pause(http_parser *parser, int paused);
/* Checks if this is the final chunk of the body. */
int http_body_is_final(const http_parser *parser);
#ifdef __cplusplus
}
#endif
View
28 test.c
@@ -67,6 +67,7 @@ struct message {
int headers_complete_cb_called;
int message_complete_cb_called;
int message_complete_on_eof;
int body_is_final;
};
static int currently_parsing_eof;
@@ -1449,12 +1450,26 @@ header_value_cb (http_parser *p, const char *buf, size_t len)
return 0;
}
void
check_body_is_final (const http_parser *p)
{
if (messages[num_messages].body_is_final) {
fprintf(stderr, "\n\n *** Error http_body_is_final() should return 1 "
"on last on_body callback call "
"but it doesn't! ***\n\n");
assert(0);
abort();
}
messages[num_messages].body_is_final = http_body_is_final(p);
}
int
body_cb (http_parser *p, const char *buf, size_t len)
{
assert(p == parser);
strncat(messages[num_messages].body, buf, len);
messages[num_messages].body_size += len;
check_body_is_final(p);
// printf("body_cb: '%s'\n", requests[num_messages].body);
return 0;
}
@@ -1465,6 +1480,7 @@ count_body_cb (http_parser *p, const char *buf, size_t len)
assert(p == parser);
assert(buf);
messages[num_messages].body_size += len;
check_body_is_final(p);
return 0;
}
@@ -1501,6 +1517,16 @@ message_complete_cb (http_parser *p)
assert(0);
abort();
}
if (messages[num_messages].body_size && http_body_is_final(p)
&& !messages[num_messages].body_is_final) {
fprintf(stderr, "\n\n *** Error http_body_is_final() should return 1 "
"on last on_body callback call "
"but it doesn't! ***\n\n");
assert(0);
abort();
}
messages[num_messages].message_complete_cb_called = TRUE;
messages[num_messages].message_complete_on_eof = currently_parsing_eof;
@@ -1891,7 +1917,7 @@ upgrade_message_fix(char *body, const size_t nread, const size_t nmsgs, ...) {
va_list ap;
size_t i;
size_t off = 0;
va_start(ap, nmsgs);
for (i = 0; i < nmsgs; i++) {
ProTip! Use n and p to navigate between commits in a pull request.