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)
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

Loading…
Cancel
Save