Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created December 4, 2012 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/4208772 to your computer and use it in GitHub Desktop.
Save isaacs/4208772 to your computer and use it in GitHub Desktop.
diff --git a/lib/http.js b/lib/http.js
index 6fffec0..6d0e374 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -294,6 +294,9 @@ function IncomingMessage(socket) {
// response (client) only
this.statusCode = null;
this.client = this.socket;
+
+ // flag for backwards compatibility grossness.
+ this._consuming = false;
}
util.inherits(IncomingMessage, Stream.Readable);
@@ -301,6 +304,12 @@ util.inherits(IncomingMessage, Stream.Readable);
exports.IncomingMessage = IncomingMessage;
+IncomingMessage.prototype.read = function(n) {
+ this._consuming = true;
+ return Stream.Readable.prototype.read.call(this, n);
+};
+
+
IncomingMessage.prototype._read = function (n, callback) {
// We actually do almost nothing here, because the parserOnBody
// function fills up our internal buffer directly. However, we
@@ -1413,11 +1422,13 @@ function socketOnData(d, start, end) {
}
+// client
function parserOnIncomingClient(res, shouldKeepAlive) {
var parser = this;
var socket = this.socket;
var req = socket._httpMessage;
+
// propogate "domain" setting...
if (req.domain && !res.domain) {
debug('setting "res.domain"');
@@ -1465,15 +1476,16 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
COUNTER_HTTP_CLIENT_RESPONSE();
- req.emit('response', res);
req.res = res;
res.req = req;
+ req.emit('response', res);
res.on('end', responseOnEnd);
return isHeadResponse;
}
+// client
function responseOnEnd() {
var res = this;
var req = res.req;
@@ -1791,6 +1803,12 @@ function connectionListener(socket) {
incoming.shift();
+ // if the user never called req.read(), and didn't pipe() or
+ // .resume() or .on('data'), then we call req.resume() so that the
+ // bytes will be pulled off the wire.
+ if (!req._consuming)
+ req.resume();
+
res.detachSocket(socket);
if (res._last) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment