Skip to content

Commit 29be1e5

Browse files
committed
http: do not replace .read() in IncomingMessage
Remove the req._consumed property, as its use is completely superseded and not needed anymore. This was being set in the overridden .read(). PR-URL: #18939 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0bff955 commit 29be1e5

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

lib/_http_incoming.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ function readStop(socket) {
3838
function IncomingMessage(socket) {
3939
Stream.Readable.call(this);
4040

41-
// Set this to `true` so that stream.Readable won't attempt to read more
42-
// data on `IncomingMessage#push` (see `maybeReadMore` in
43-
// `_stream_readable.js`). This is important for proper tracking of
44-
// `IncomingMessage#_consuming` which is used to dump requests that users
45-
// haven't attempted to read.
46-
this._readableState.readingMore = true;
47-
4841
this.socket = socket;
4942
this.connection = socket;
5043

@@ -70,9 +63,6 @@ function IncomingMessage(socket) {
7063
this.statusMessage = null;
7164
this.client = socket;
7265

73-
// flag for backwards compatibility grossness.
74-
this._consuming = false;
75-
7666
// flag for when we decide that this message cannot possibly be
7767
// read by the user, so there's no point continuing to handle it.
7868
this._dumped = false;
@@ -88,15 +78,6 @@ IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) {
8878
};
8979

9080

91-
IncomingMessage.prototype.read = function read(n) {
92-
if (!this._consuming)
93-
this._readableState.readingMore = false;
94-
this._consuming = true;
95-
this.read = Stream.Readable.prototype.read;
96-
return this.read(n);
97-
};
98-
99-
10081
IncomingMessage.prototype._read = function _read(n) {
10182
// We actually do almost nothing here, because the parserOnBody
10283
// function fills up our internal buffer directly. However, we
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const http = require('http');
5+
const fs = require('fs');
6+
7+
const server = http.createServer(function(req, res) {
8+
// this checks if the request gets dumped
9+
req.on('resume', common.mustCall(function() {
10+
console.log('resume called');
11+
12+
req.on('data', common.mustCallAtLeast(function(d) {
13+
console.log('data', d);
14+
}, 1));
15+
}));
16+
17+
// end is not called as we are just exhausting
18+
// the in-memory buffer
19+
req.on('end', common.mustNotCall);
20+
21+
// this 'data' handler will be removed when dumped
22+
req.on('data', common.mustNotCall);
23+
24+
// start sending the response
25+
res.flushHeaders();
26+
27+
setTimeout(function() {
28+
res.end('hello world');
29+
}, common.platformTimeout(100));
30+
});
31+
32+
server.listen(0, function() {
33+
const req = http.request({
34+
method: 'POST',
35+
port: server.address().port
36+
});
37+
38+
// Send the http request without waiting
39+
// for the body
40+
req.flushHeaders();
41+
42+
req.on('response', common.mustCall(function(res) {
43+
// pipe the body as soon as we get the headers of the
44+
// response back
45+
fs.createReadStream(__filename).pipe(req);
46+
47+
res.resume();
48+
49+
// wait for the response
50+
res.on('end', function() {
51+
server.close();
52+
});
53+
}));
54+
});

0 commit comments

Comments
 (0)