http_should_keep_alive returns 1 for HTTP/1.0
It appears there is a slight bug with http_should_keep_alive with HTTP/1.0 here:
int
http_should_keep_alive (const http_parser *parser)
{
// should be parser->http_major >= 1 && parser->http_minor > 0
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);
}
No, it seems to be correct. First clause matches version >= 1.1 and latter matches the rest.
It does work for HTTP <= 1.1, but it's not perfect, as it would match on 2.1 but not 2.0.
Should be something more like:
if ((parser->http_major == 1 && parser->http_minor >= 1) ||
parser->http_major > 1)
Considering that HTTP 2.0 has completely different protocol this seems to be fine, though ;)
Then change it to
if (parser->http_major == 1 && parser->http_minor >= 1)
It looks like an error to me as well. As craig says, then, we're deciding to restrict to >= 1.1 and < 2.0? Hence a change to ==.
This is pointless, the idea of function is to test if connection is keep-alive by default, and it is if the version is < 1.1.