Browse Source

http: Use stream.push() instead of touching _readableState

v0.9.6-release
isaacs 12 years ago
parent
commit
bc8feb151c
  1. 22
      lib/http.js

22
lib/http.js

@ -122,17 +122,15 @@ function parserOnBody(b, start, len) {
if (!stream) if (!stream)
return; return;
var rs = stream._readableState;
var socket = stream.socket; var socket = stream.socket;
// pretend this was the result of a stream._read call. // 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); 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() { function parserOnMessageComplete() {
@ -155,14 +153,12 @@ function parserOnMessageComplete() {
if (!stream.upgrade) if (!stream.upgrade)
// For upgraded connections, also emit this after parser.execute // For upgraded connections, also emit this after parser.execute
stream._readableState.onread(null, null); stream.push(null);
} }
if (stream && if (stream && !parser.incoming._pendings.length) {
!stream._readableState.endEmitted &&
!parser.incoming._pendings.length) {
// For emit end event // For emit end event
stream._readableState.onread(null, null); stream.push(null);
} }
if (parser.socket.readable) { if (parser.socket.readable) {
@ -402,7 +398,7 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) {
IncomingMessage.prototype._dump = function() { IncomingMessage.prototype._dump = function() {
this._dumped = true; this._dumped = true;
this.socket.parser.incoming = null; this.socket.parser.incoming = null;
this._readableState.onread(null, null); this.push(null);
this.socket.resume(); this.socket.resume();
}; };
@ -1363,7 +1359,7 @@ function socketCloseListener() {
res.on('end', function() { res.on('end', function() {
res.emit('close'); res.emit('close');
}); });
res._readableState.onread(null, null); res.push(null);
} else if (!req.res && !req._hadError) { } else if (!req.res && !req._hadError) {
// This socket error fired before we started to // This socket error fired before we started to
// receive a response. The error needs to // receive a response. The error needs to

Loading…
Cancel
Save