joyent/node — pull request #8439 by tjfontaine (2014-09-24 16:13:05+00:00)
Title: Handle trailing bytes for chunked encoding more gracefully

http requests may encounter a response stream that outputs extra bytes -- for instance see 1fddc1fee84785d296e37337dcb0dc12c13a049f where Node.js itself was sending too much. In that case our parser will currently give a parse error, which results in us unilaterally destroying the socket and raising an error on the `request` (not the `response`).

This change adds an event `chunkedRemainingBytes` which will be emitted on the `response` object, that callback will be passed the bytes that we were unable to parse. If there is no listener for this event we will fall back to the previous behavior. The documentation includes some mediation for detecting this case, but it cannot interrupt the socket from being destroyed.

As part of this PR, I also have a commit that partially reverts 1fddc1fee84785d296e37337dcb0dc12c13a049f, it was opting out of the hot path detection code for responses that have a body, resulting in the many pipeline test taking too long and timing out particularly on linux.

/cc @indutny @trevnorris