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

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
from

Conversation

Projects
None yet
3 participants
Contributor

bog-dan-ro commented Aug 31, 2012

It's useful to check if the current chunk is the last one.

@bnoordhuis bnoordhuis and 1 other commented on an outdated diff Aug 31, 2012

http_parser.c
@@ -2175,3 +2175,8 @@ size_t http_parser_execute (http_parser *parser,
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)?1:0;
@bnoordhuis

bnoordhuis Aug 31, 2012

Member

Non-idiomatic code, use return parser->state == s_message_done;

@bog-dan-ro

bog-dan-ro Aug 31, 2012

Contributor

Done

@bnoordhuis bnoordhuis and 1 other commented on an outdated diff Aug 31, 2012

http_parser.h
@@ -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 */
@bnoordhuis

bnoordhuis Aug 31, 2012

Member

s/checks/Checks/ and add punctuation. (Yes, I'm a language/grammar Nazi).

@bog-dan-ro

bog-dan-ro Aug 31, 2012

Contributor

Done :)

@bnoordhuis bnoordhuis and 1 other commented on an outdated diff Aug 31, 2012

test.c
@@ -1449,12 +1450,27 @@ struct message {
return 0;
}
+void
+check_body_is_final (const http_parser *p)
+{
+ if (messages[num_messages].body_is_final)
+ {
@bnoordhuis

bnoordhuis Aug 31, 2012

Member

Style: brace on the same line.

@bog-dan-ro

bog-dan-ro Aug 31, 2012

Contributor

Done.

@bnoordhuis bnoordhuis and 1 other commented on an outdated diff Aug 31, 2012

test.c
@@ -1501,6 +1518,16 @@ struct message {
assert(0);
abort();
}
+
+ if (messages[num_messages].body_size && http_body_is_final(p) && !messages[num_messages].body_is_final)
@bnoordhuis

bnoordhuis Aug 31, 2012

Member

Long line, wrap at 80 columns.

@bog-dan-ro

bog-dan-ro Aug 31, 2012

Contributor

Done.

Contributor

udp commented Aug 31, 2012

Maybe http_message_is_complete would be a clearer name than http_body_is_final?

Member

bnoordhuis commented Aug 31, 2012

Some style issues but generally LGTM.

Member

bnoordhuis commented Aug 31, 2012

Maybe http_message_is_complete would be a clearer name than http_body_is_final?

Yes, I can live with that.

Add "int http_body_is_final(const http_parser *parser)" method.
It's useful to check if the current chunk is the last one.

@bog-dan-ro bog-dan-ro closed this Aug 31, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment