Skip to content

Commit

Permalink
http: don't unset hot path for responses with body
Browse files Browse the repository at this point in the history
Revert a regression introduced when avoiding extra bytes for HEAD
requests, we shouldn't drop out of the hot path when responses will have
a body.
  • Loading branch information
tjfontaine committed Sep 24, 2014
1 parent c8e0bdd commit 7e54885
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/http.js
Expand Up @@ -954,6 +954,7 @@ OutgoingMessage.prototype.end = function(data, encoding) {
// res.writeHead();
// res.end(blah);
// HACKY.
debug('we have hot path');

if (typeof data === 'string') {
if (this.chunkedEncoding) {
Expand Down Expand Up @@ -1586,11 +1587,21 @@ function socketOnData(d, start, end) {

var ret = parser.execute(d, start, end - start);
if (ret instanceof Error) {
debug('parse error');
freeParser(parser, req);
socket.destroy();
req.emit('error', ret);
req._hadError = true;
var response = parser.incoming;
if (response &&
response.headers['transfer-encoding'] === 'chunked' &&
response.complete &&
EventEmitter.listenerCount(response, 'chunkedRemainingBytes') > 0) {
var buff = d.slice(start + ret.bytesParsed, end);
debug('chunked encoding stream had extra bytes ' + ret.bytesParsed + ' ' + buff.length);
response.emit('chunkedRemainingBytes', buff);
} else {
debug('parse error');
freeParser(parser, req);
socket.destroy();
req.emit('error', ret);
req._hadError = true;
}
} else if (parser.incoming && parser.incoming.upgrade) {
// Upgrade or CONNECT
var bytesParsed = ret;
Expand Down

0 comments on commit 7e54885

Please sign in to comment.