From d84b49eccc5e9a578b14ed0fe8409318319448d1 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 17 Oct 2017 22:19:27 +0200 Subject: [PATCH] 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 Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig Reviewed-By: Anatoli Papirovski --- doc/api/http.md | 16 +++--- lib/_http_client.js | 5 +- lib/_http_server.js | 22 +++++--- test/parallel/test-http-generic-streams.js | 60 ++++++++++++++++++++++ 4 files changed, 88 insertions(+), 15 deletions(-) create mode 100644 test/parallel/test-http-generic-streams.js diff --git a/doc/api/http.md b/doc/api/http.md index e4300cc429..4a84e50ba0 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -797,11 +797,14 @@ added: v0.1.0 * `socket` {net.Socket} -When a new TCP stream is established. `socket` is an object of type -[`net.Socket`][]. Usually users will not want to access this event. In -particular, the socket will not emit `'readable'` events because of how -the protocol parser attaches to the socket. The `socket` can also be -accessed at `request.connection`. +This event is emitted when a new TCP stream is established. `socket` is +typically an object of type [`net.Socket`][]. Usually users will not want to +access this event. In particular, the socket will not emit `'readable'` events +because of how the protocol parser attaches to the socket. The `socket` can +also be accessed at `request.connection`. + +*Note*: This event can also be explicitly emitted by users to inject connections +into the HTTP server. In that case, any [`Duplex`][] stream can be passed. ### Event: 'request'