http-parser icon indicating copy to clipboard operation
http-parser copied to clipboard

http_should_keep_alive returns 1 for HTTP/1.0

Open jasongilanfarr opened this issue 12 years ago • 6 comments

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);
}

jasongilanfarr avatar Jan 14 '14 21:01 jasongilanfarr

No, it seems to be correct. First clause matches version >= 1.1 and latter matches the rest.

indutny avatar Jan 23 '14 11:01 indutny

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)

craig65535 avatar Feb 12 '14 23:02 craig65535

Considering that HTTP 2.0 has completely different protocol this seems to be fine, though ;)

indutny avatar Feb 13 '14 06:02 indutny

Then change it to

if (parser->http_major == 1 && parser->http_minor >= 1)

craig65535 avatar Feb 18 '14 21:02 craig65535

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 ==.

stephenamills avatar Feb 18 '14 23:02 stephenamills

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.

indutny avatar Feb 19 '14 08:02 indutny