summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-12-18 18:49:09 -0800
committerisaacs <i@izs.me>2012-12-21 00:07:34 +0000
commit8624adf5d8b7e0429f7c127a2ede855680fe5c18 (patch)
tree78200cd6cc8efdac342e04a0d7ef72c216210d0d
parent836593da23f753cb687ed0ee97410d635cf04c9f (diff)
downloadnode-8624adf5d8b7e0429f7c127a2ede855680fe5c18.tar.gz
http: use IncomingMessage._dump() instead of resume()
-rw-r--r--lib/http.js83
1 files changed, 35 insertions, 48 deletions
diff --git a/lib/http.js b/lib/http.js
index cdfc17b87..2e1cc84da 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -119,6 +119,11 @@ function parserOnHeadersComplete(info) {
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;
@@ -135,29 +140,29 @@ function parserOnBody(b, start, len) {
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();
}
}
@@ -307,6 +312,7 @@ exports.IncomingMessage = IncomingMessage;
IncomingMessage.prototype.read = function(n) {
this._consuming = true;
+ this.read = Stream.Readable.prototype.read;
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
//
// 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() {
Stream.call(this);
@@ -1534,7 +1521,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
// 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;
}
@@ -1861,7 +1848,7 @@ function connectionListener(socket) {
// .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);