http: use IncomingMessage._dump() instead of resume()
This commit is contained in:
parent
836593da23
commit
8624adf5d8
55
lib/http.js
55
lib/http.js
@ -119,6 +119,11 @@ function parserOnHeadersComplete(info) {
|
|||||||
function parserOnBody(b, start, len) {
|
function parserOnBody(b, start, len) {
|
||||||
var parser = this;
|
var parser = this;
|
||||||
var stream = parser.incoming;
|
var stream = parser.incoming;
|
||||||
|
|
||||||
|
// if the stream has already been removed, then drop it.
|
||||||
|
if (!stream)
|
||||||
|
return;
|
||||||
|
|
||||||
var rs = stream._readableState;
|
var rs = stream._readableState;
|
||||||
var socket = stream.socket;
|
var socket = stream.socket;
|
||||||
|
|
||||||
@ -135,10 +140,9 @@ function parserOnBody(b, start, len) {
|
|||||||
function parserOnMessageComplete() {
|
function parserOnMessageComplete() {
|
||||||
var parser = this;
|
var parser = this;
|
||||||
var stream = parser.incoming;
|
var stream = parser.incoming;
|
||||||
var socket = stream.socket;
|
|
||||||
|
|
||||||
|
if (stream) {
|
||||||
stream.complete = true;
|
stream.complete = true;
|
||||||
|
|
||||||
// Emit any trailing headers.
|
// Emit any trailing headers.
|
||||||
var headers = parser._headers;
|
var headers = parser._headers;
|
||||||
if (headers) {
|
if (headers) {
|
||||||
@ -154,10 +158,11 @@ 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._readableState.onread(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
if (parser.socket.readable) {
|
if (parser.socket.readable) {
|
||||||
// force to read the next incoming message
|
// force to read the next incoming message
|
||||||
socket.resume();
|
parser.socket.resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,6 +312,7 @@ exports.IncomingMessage = IncomingMessage;
|
|||||||
|
|
||||||
IncomingMessage.prototype.read = function(n) {
|
IncomingMessage.prototype.read = function(n) {
|
||||||
this._consuming = true;
|
this._consuming = true;
|
||||||
|
this.read = Stream.Readable.prototype.read;
|
||||||
return Stream.Readable.prototype.read.call(this, n);
|
return Stream.Readable.prototype.read.call(this, n);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -327,35 +333,6 @@ IncomingMessage.prototype.destroy = function(error) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IncomingMessage.prototype._emitData = function(d) {
|
|
||||||
if (this._decoder) {
|
|
||||||
var string = this._decoder.write(d);
|
|
||||||
if (string.length) {
|
|
||||||
this.emit('data', string);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.emit('data', d);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
IncomingMessage.prototype._emitEnd = function() {
|
|
||||||
if (!this._endEmitted) {
|
|
||||||
if (this._decoder) {
|
|
||||||
var ret = this._decoder.end();
|
|
||||||
if (ret)
|
|
||||||
this.emit('data', ret);
|
|
||||||
}
|
|
||||||
this.emit('end');
|
|
||||||
}
|
|
||||||
|
|
||||||
this._endEmitted = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Add the given (field, value) pair to the message
|
// Add the given (field, value) pair to the message
|
||||||
//
|
//
|
||||||
// Per RFC2616, section 4.2 it is acceptable to join multiple instances of the
|
// Per RFC2616, section 4.2 it is acceptable to join multiple instances of the
|
||||||
@ -415,6 +392,16 @@ IncomingMessage.prototype._addHeaderLine = function(field, value) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Call this instead of resume() if we want to just
|
||||||
|
// dump all the data to /dev/null
|
||||||
|
IncomingMessage.prototype._dump = function() {
|
||||||
|
this._dumped = true;
|
||||||
|
this.socket.parser.incoming = null;
|
||||||
|
this._readableState.onread(null, null);
|
||||||
|
this.socket.resume();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
function OutgoingMessage() {
|
function OutgoingMessage() {
|
||||||
Stream.call(this);
|
Stream.call(this);
|
||||||
|
|
||||||
@ -1534,7 +1521,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
|
|||||||
// can't possibly read the data, so we .resume() it into the void
|
// can't possibly read the data, so we .resume() it into the void
|
||||||
// so that the socket doesn't hang there in a paused state.
|
// so that the socket doesn't hang there in a paused state.
|
||||||
if (!handled)
|
if (!handled)
|
||||||
res.resume();
|
res._dump();
|
||||||
|
|
||||||
return isHeadResponse;
|
return isHeadResponse;
|
||||||
}
|
}
|
||||||
@ -1861,7 +1848,7 @@ function connectionListener(socket) {
|
|||||||
// .resume() or .on('data'), then we call req.resume() so that the
|
// .resume() or .on('data'), then we call req.resume() so that the
|
||||||
// bytes will be pulled off the wire.
|
// bytes will be pulled off the wire.
|
||||||
if (!req._consuming)
|
if (!req._consuming)
|
||||||
req.resume();
|
req._dump();
|
||||||
|
|
||||||
res.detachSocket(socket);
|
res.detachSocket(socket);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user