function parserOnBody(b, start, len) {
var parser = this;
var stream = parser.incoming;
+
+ // if the stream has already been removed, then drop it.
+ if (!stream)
+ return;
+
var rs = stream._readableState;
var socket = stream.socket;
function parserOnMessageComplete() {
var parser = this;
var stream = parser.incoming;
- var socket = stream.socket;
- stream.complete = true;
-
- // Emit any trailing headers.
- var headers = parser._headers;
- if (headers) {
- for (var i = 0, n = headers.length; i < n; i += 2) {
- var k = headers[i];
- var v = headers[i + 1];
- parser.incoming._addHeaderLine(k, v);
+ if (stream) {
+ stream.complete = true;
+ // Emit any trailing headers.
+ var headers = parser._headers;
+ if (headers) {
+ for (var i = 0, n = headers.length; i < n; i += 2) {
+ var k = headers[i];
+ var v = headers[i + 1];
+ parser.incoming._addHeaderLine(k, v);
+ }
+ parser._headers = [];
+ parser._url = '';
}
- parser._headers = [];
- parser._url = '';
- }
- if (!stream.upgrade)
- // For upgraded connections, also emit this after parser.execute
- stream._readableState.onread(null, null);
+ if (!stream.upgrade)
+ // For upgraded connections, also emit this after parser.execute
+ stream._readableState.onread(null, null);
+ }
if (parser.socket.readable) {
// force to read the next incoming message
- socket.resume();
+ parser.socket.resume();
}
}
IncomingMessage.prototype.read = function(n) {
this._consuming = true;
+ this.read = Stream.Readable.prototype.read;
return Stream.Readable.prototype.read.call(this, n);
};
};
-
-
-
-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
//
// Per RFC2616, section 4.2 it is acceptable to join multiple instances of the
};
+// 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() {
Stream.call(this);
// 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.
if (!handled)
- res.resume();
+ res._dump();
return isHeadResponse;
}
// .resume() or .on('data'), then we call req.resume() so that the
// bytes will be pulled off the wire.
if (!req._consuming)
- req.resume();
+ req._dump();
res.detachSocket(socket);