Don't wait for EOF on 0-length KA messages.

- Break EOF handling out of http_should_keep_alive() into
  http_message_needs_eof(), which we now use when determining what to do
  with a message of unknown length. This prevents us from falling into
  the s_body_identity_eof state in the cases where we actually *do* know
  the length of the message (e.g. because the response status was 204).
v0.10
Peter Griess 13 years ago
parent 248fbc3ab4
commit b115d110a3

@ -358,6 +358,8 @@ static struct {
};
#undef HTTP_STRERROR_GEN
int http_message_needs_eof(http_parser *parser);
/* Our URL parser.
*
* This is designed to be shared by http_parser_execute() for URL validation,
@ -1541,7 +1543,8 @@ size_t http_parser_execute (http_parser *parser,
/* Content-Length header given and non-zero */
state = s_body_identity;
} else {
if (parser->type == HTTP_REQUEST || http_should_keep_alive(parser)) {
if (parser->type == HTTP_REQUEST ||
!http_message_needs_eof(parser)) {
/* Assume content-length 0 - read the next */
CALLBACK2(message_complete);
state = NEW_MESSAGE();
@ -1704,23 +1707,12 @@ error:
}
/* Does the parser need to see an EOF to find the end of the message? */
int
http_should_keep_alive (http_parser *parser)
http_message_needs_eof (http_parser *parser)
{
if (parser->http_major > 0 && parser->http_minor > 0) {
/* HTTP/1.1 */
if (parser->flags & F_CONNECTION_CLOSE) {
return 0;
}
} else {
/* HTTP/1.0 or earlier */
if (!(parser->flags & F_CONNECTION_KEEP_ALIVE)) {
return 0;
}
}
if (parser->type == HTTP_REQUEST) {
return 1;
return 0;
}
/* See RFC 2616 section 4.4 */
@ -1728,14 +1720,33 @@ http_should_keep_alive (http_parser *parser)
parser->status_code == 204 || /* No Content */
parser->status_code == 304 || /* Not Modified */
parser->flags & F_SKIPBODY) { /* response to a HEAD request */
return 1;
return 0;
}
if (parser->flags & F_CHUNKED || parser->content_length >= 0) {
return 1;
if ((parser->flags & F_CHUNKED) || parser->content_length >= 0) {
return 0;
}
return 1;
}
int
http_should_keep_alive (http_parser *parser)
{
if (parser->http_major > 0 && parser->http_minor > 0) {
/* HTTP/1.1 */
if (parser->flags & F_CONNECTION_CLOSE) {
return 0;
}
} else {
/* HTTP/1.0 or earlier */
if (!(parser->flags & F_CONNECTION_KEEP_ALIVE)) {
return 0;
}
}
return !http_message_needs_eof(parser);
}

@ -1218,7 +1218,7 @@ const struct message responses[] =
"Connection: close\r\n"
"\r\n"
,.should_keep_alive= FALSE
,.message_complete_on_eof= TRUE
,.message_complete_on_eof= FALSE
,.http_major= 1
,.http_minor= 1
,.status_code= 204

Loading…
Cancel
Save