Skip to content

Commit f0201c1

Browse files
committed
stream: add readableDidRead
Adds readableDidRead to streams and applies usage to http, http2 and quic. PR-URL: nodejs#36820 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 7410d41 commit f0201c1

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/_http_incoming.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ function IncomingMessage(socket) {
8787
this.statusMessage = null;
8888
this.client = socket;
8989

90+
// TODO: Deprecate and remove.
9091
this._consuming = false;
9192
// Flag for when we decide that this message cannot possibly be
9293
// read by the user, so there's no point continuing to handle it.

lib/_http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ function resOnFinish(req, res, socket, state, server) {
804804
// If the user never called req.read(), and didn't pipe() or
805805
// .resume() or .on('data'), then we call req._dump() so that the
806806
// bytes will be pulled off the wire.
807-
if (!req._consuming && !req._readableState.resumeScheduled)
807+
if (!req.readableDidRead)
808808
req._dump();
809809

810810
// Make sure the requestTimeout is cleared before finishing.

lib/internal/streams/readable.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ Readable.prototype.read = function(n) {
527527
this.emit('data', ret);
528528
}
529529

530+
state.didRead = true;
531+
530532
return ret;
531533
};
532534

@@ -830,7 +832,9 @@ function pipeOnDrain(src, dest) {
830832

831833
if ((!state.awaitDrainWriters || state.awaitDrainWriters.size === 0) &&
832834
EE.listenerCount(src, 'data')) {
835+
// TODO(ronag): Call resume() instead?
833836
state.flowing = true;
837+
state.didRead = true;
834838
flow(src);
835839
}
836840
};
@@ -978,6 +982,7 @@ Readable.prototype.resume = function() {
978982
function resume(stream, state) {
979983
if (!state.resumeScheduled) {
980984
state.resumeScheduled = true;
985+
state.didRead = true;
981986
process.nextTick(resume_, stream, state);
982987
}
983988
}
@@ -1191,12 +1196,16 @@ ObjectDefineProperties(Readable.prototype, {
11911196
readableDidRead: {
11921197
enumerable: false,
11931198
get: function() {
1199+
<<<<<<< HEAD
11941200
return (
11951201
this._readableState.dataEmitted ||
11961202
this._readableState.endEmitted ||
11971203
this._readableState.errorEmitted ||
11981204
this._readableState.closeEmitted
11991205
);
1206+
=======
1207+
return this._readableState.didRead;
1208+
>>>>>>> 8fe7d23c17... stream: add readableDidRead
12001209
}
12011210
},
12021211

0 commit comments

Comments
 (0)