Skip to content

Commit 9bd7492

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 a6d50a1 commit 9bd7492

3 files changed

Lines changed: 7 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: 5 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
}

0 commit comments

Comments
 (0)