From bc8feb151c731f5862a02fccb58638105b44d45b Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 7 Jan 2013 20:23:07 -0800 Subject: [PATCH] http: Use stream.push() instead of touching _readableState --- lib/http.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/http.js b/lib/http.js index 4114f213c3..1bf85d234a 100644 --- a/lib/http.js +++ b/lib/http.js @@ -122,17 +122,15 @@ function parserOnBody(b, start, len) { if (!stream) return; - var rs = stream._readableState; var socket = stream.socket; // pretend this was the result of a stream._read call. - if (len > 0) { + if (len > 0 && !stream._dumped) { var slice = b.slice(start, start + len); - rs.onread(null, slice); + var ret = stream.push(slice); + if (!ret) + socket.pause(); } - - if (rs.length >= rs.highWaterMark) - socket.pause(); } function parserOnMessageComplete() { @@ -155,14 +153,12 @@ function parserOnMessageComplete() { if (!stream.upgrade) // For upgraded connections, also emit this after parser.execute - stream._readableState.onread(null, null); + stream.push(null); } - if (stream && - !stream._readableState.endEmitted && - !parser.incoming._pendings.length) { + if (stream && !parser.incoming._pendings.length) { // For emit end event - stream._readableState.onread(null, null); + stream.push(null); } if (parser.socket.readable) { @@ -402,7 +398,7 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) { IncomingMessage.prototype._dump = function() { this._dumped = true; this.socket.parser.incoming = null; - this._readableState.onread(null, null); + this.push(null); this.socket.resume(); }; @@ -1363,7 +1359,7 @@ function socketCloseListener() { res.on('end', function() { res.emit('close'); }); - res._readableState.onread(null, null); + res.push(null); } else if (!req.res && !req._hadError) { // This socket error fired before we started to // receive a response. The error needs to