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 #undef HTTP_STRERROR_GEN
int http_message_needs_eof(http_parser *parser);
/* Our URL parser. /* Our URL parser.
* *
* This is designed to be shared by http_parser_execute() for URL validation, * 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 */ /* Content-Length header given and non-zero */
state = s_body_identity; state = s_body_identity;
} else { } 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 */ /* Assume content-length 0 - read the next */
CALLBACK2(message_complete); CALLBACK2(message_complete);
state = NEW_MESSAGE(); state = NEW_MESSAGE();
@ -1704,6 +1707,30 @@ error:
} }
/* Does the parser need to see an EOF to find the end of the message? */
int
http_message_needs_eof (http_parser *parser)
{
if (parser->type == HTTP_REQUEST) {
return 0;
}
/* See RFC 2616 section 4.4 */
if (parser->status_code / 100 == 1 || /* 1xx e.g. Continue */
parser->status_code == 204 || /* No Content */
parser->status_code == 304 || /* Not Modified */
parser->flags & F_SKIPBODY) { /* response to a HEAD request */
return 0;
}
if ((parser->flags & F_CHUNKED) || parser->content_length >= 0) {
return 0;
}
return 1;
}
int int
http_should_keep_alive (http_parser *parser) http_should_keep_alive (http_parser *parser)
{ {
@ -1719,23 +1746,7 @@ http_should_keep_alive (http_parser *parser)
} }
} }
if (parser->type == HTTP_REQUEST) { return !http_message_needs_eof(parser);
return 1;
}
/* See RFC 2616 section 4.4 */
if (parser->status_code / 100 == 1 || /* 1xx e.g. Continue */
parser->status_code == 204 || /* No Content */
parser->status_code == 304 || /* Not Modified */
parser->flags & F_SKIPBODY) { /* response to a HEAD request */
return 1;
}
if (parser->flags & F_CHUNKED || parser->content_length >= 0) {
return 1;
}
return 0;
} }

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

Loading…
Cancel
Save