tmm1/http_parser.rb — pull request #41 by robertjpayne (2014-08-25 00:07:34+00:00)
Title: Better handling of upgraded connections

Upgraded connections are one of either:

* A HTTP request with headers of `Connection: upgrade`
* A HTTP CONNECT request

The parser has a few flaws around upgraded connections:

* It’s assuming all upgraded connections, if aborted are aborted in the headers stage in which you have to increment the number of bytes consumed due the way http_parser.c works
* It’s also assuming all upgraded connections have at least 1 byte or more of "extra" data by the time the parser’s state is set to upgrade.

This pull request fixes both:

* Ensure to only increment the number of bytes consumed by 1 if the message is not completed
* Ensure if the number of bytes consumed is not greater than the total bytes provided we don’t attempt to set the upgrade_data.

There’s also test cases added to ensure compatibility.