mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
http: support generic Duplex streams
Support generic `Duplex` streams through more duck typing on the server and client sides. Since HTTP is, as a protocol, independent of its underlying transport layer, Node.js should not enforce any restrictions on what streams its HTTP parser may use. Ref: https://github.com/nodejs/node/issues/16256 PR-URL: https://github.com/nodejs/node/pull/16267 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
4 files changed
+88
-15
No files matched your search
+14
-8
@@ -303,7 +303,7 @@ function connectionListener(socket) {
|
||||
// If the user has added a listener to the server,
|
||||
// request, or response, then it's their responsibility.
|
||||
// otherwise, destroy on timeout by default
|
||||
if (this.timeout)
|
||||
if (this.timeout && typeof socket.setTimeout === 'function')
|
||||
socket.setTimeout(this.timeout);
|
||||
socket.on('timeout', socketOnTimeout);
|
||||
|
||||
@@ -354,11 +354,13 @@ function connectionListener(socket) {
|
||||
socket.on = socketOnWrap;
|
||||
|
||||
// We only consume the socket if it has never been consumed before.
|
||||
var external = socket._handle._externalStream;
|
||||
if (!socket._handle._consumed && external) {
|
||||
parser._consumed = true;
|
||||
socket._handle._consumed = true;
|
||||
parser.consume(external);
|
||||
if (socket._handle) {
|
||||
var external = socket._handle._externalStream;
|
||||
if (!socket._handle._consumed && external) {
|
||||
parser._consumed = true;
|
||||
socket._handle._consumed = true;
|
||||
parser.consume(external);
|
||||
}
|
||||
}
|
||||
parser[kOnExecute] =
|
||||
onParserExecute.bind(undefined, this, socket, parser, state);
|
||||
@@ -533,9 +535,13 @@ function resOnFinish(req, res, socket, state, server) {
|
||||
res.detachSocket(socket);
|
||||
|
||||
if (res._last) {
|
||||
socket.destroySoon();
|
||||
if (typeof socket.destroySoon === 'function') {
|
||||
socket.destroySoon();
|
||||
} else {
|
||||
socket.end();
|
||||
}
|
||||
} else if (state.outgoing.length === 0) {
|
||||
if (server.keepAliveTimeout) {
|
||||
if (server.keepAliveTimeout && typeof socket.setTimeout === 'function') {
|
||||
socket.setTimeout(0);
|
||||
socket.setTimeout(server.keepAliveTimeout);
|
||||
state.keepAliveTimeoutSet = true;
|
||||
|
||||
Reference in new issue
Block a user