@@ -157,7 +157,7 @@ added: v0.11.4
157157* ` options ` {Object} Options containing connection details. Check
158158 [ ` net.createConnection() ` ] [ ] for the format of the options
159159* ` callback ` {Function} Callback function that receives the created socket
160- * Returns: {net.Socket }
160+ * Returns: {stream.Duplex }
161161
162162Produces a socket/stream to be used for HTTP requests.
163163
@@ -167,14 +167,18 @@ custom agents may override this method in case greater flexibility is desired.
167167A socket/stream can be supplied in one of two ways: by returning the
168168socket/stream from this function, or by passing the socket/stream to ` callback ` .
169169
170+ This method is guaranteed to return an instance of the {net.Socket} class,
171+ a subclass of {stream.Duplex}, unless the user specifies a socket
172+ type other than {net.Socket}.
173+
170174` callback ` has a signature of ` (err, stream) ` .
171175
172176### ` agent.keepSocketAlive(socket) `
173177<!-- YAML
174178added: v8.1.0
175179-->
176180
177- * ` socket ` {net.Socket }
181+ * ` socket ` {stream.Duplex }
178182
179183Called when ` socket ` is detached from a request and could be persisted by the
180184` Agent ` . Default behavior is to:
@@ -189,12 +193,15 @@ This method can be overridden by a particular `Agent` subclass. If this
189193method returns a falsy value, the socket will be destroyed instead of persisting
190194it for use with the next request.
191195
196+ The ` socket ` argument can be an instance of {net.Socket}, a subclass of
197+ {stream.Duplex}.
198+
192199### ` agent.reuseSocket(socket, request) `
193200<!-- YAML
194201added: v8.1.0
195202-->
196203
197- * ` socket ` {net.Socket }
204+ * ` socket ` {stream.Duplex }
198205* ` request ` {http.ClientRequest}
199206
200207Called when ` socket ` is attached to ` request ` after being persisted because of
@@ -206,6 +213,9 @@ socket.ref();
206213
207214This method can be overridden by a particular ` Agent ` subclass.
208215
216+ The ` socket ` argument can be an instance of {net.Socket}, a subclass of
217+ {stream.Duplex}.
218+
209219### ` agent.destroy() `
210220<!-- YAML
211221added: v0.11.4
@@ -341,13 +351,17 @@ added: v0.7.0
341351-->
342352
343353* ` response ` {http.IncomingMessage}
344- * ` socket ` {net.Socket }
354+ * ` socket ` {stream.Duplex }
345355* ` head ` {Buffer}
346356
347357Emitted each time a server responds to a request with a ` CONNECT ` method. If
348358this event is not being listened for, clients receiving a ` CONNECT ` method will
349359have their connections closed.
350360
361+ This event is guaranteed to be passed an instance of the {net.Socket} class,
362+ a subclass of {stream.Duplex}, unless the user specifies a socket
363+ type other than {net.Socket}.
364+
351365A client and server pair demonstrating how to listen for the ` 'connect' ` event:
352366
353367``` js
@@ -471,9 +485,11 @@ once.
471485added: v0.5.3
472486-->
473487
474- * ` socket ` {net.Socket }
488+ * ` socket ` {stream.Duplex }
475489
476- Emitted after a socket is assigned to this request.
490+ This event is guaranteed to be passed an instance of the {net.Socket} class,
491+ a subclass of {stream.Duplex}, unless the user specifies a socket
492+ type other than {net.Socket}.
477493
478494### Event: ` 'timeout' `
479495<!-- YAML
@@ -491,14 +507,18 @@ added: v0.1.94
491507-->
492508
493509* ` response ` {http.IncomingMessage}
494- * ` socket ` {net.Socket }
510+ * ` socket ` {stream.Duplex }
495511* ` head ` {Buffer}
496512
497513Emitted each time a server responds to a request with an upgrade. If this
498514event is not being listened for and the response status code is 101 Switching
499515Protocols, clients receiving an upgrade header will have their connections
500516closed.
501517
518+ This event is guaranteed to be passed an instance of the {net.Socket} class,
519+ a subclass of {stream.Duplex}, unless the user specifies a socket
520+ type other than {net.Socket}.
521+
502522A client server pair demonstrating how to listen for the ` 'upgrade' ` event.
503523
504524``` js
@@ -569,7 +589,7 @@ been aborted.
569589added: v0.3.0
570590-->
571591
572- * {net.Socket }
592+ * {stream.Duplex }
573593
574594See [ ` request.socket ` ] [ ] .
575595
@@ -797,7 +817,7 @@ Once a socket is assigned to this request and is connected
797817added: v0.3.0
798818-->
799819
800- * {net.Socket }
820+ * {stream.Duplex }
801821
802822Reference to the underlying socket. Usually users will not want to access
803823this property. In particular, the socket will not emit ` 'readable' ` events
@@ -819,6 +839,10 @@ req.once('response', (res) => {
819839});
820840```
821841
842+ This property is guaranteed to be an instance of the {net.Socket} class,
843+ a subclass of {stream.Duplex}, unless the user specified a socket
844+ type other than {net.Socket}.
845+
822846### ` request.writableEnded `
823847<!-- YAML
824848added: v12.9.0
@@ -932,13 +956,17 @@ changes:
932956-->
933957
934958* ` exception ` {Error}
935- * ` socket ` {net.Socket }
959+ * ` socket ` {stream.Duplex }
936960
937961If a client connection emits an ` 'error' ` event, it will be forwarded here.
938962Listener of this event is responsible for closing/destroying the underlying
939963socket. For example, one may wish to more gracefully close the socket with a
940964custom HTTP response instead of abruptly severing the connection.
941965
966+ This event is guaranteed to be passed an instance of the {net.Socket} class,
967+ a subclass of {stream.Duplex}, unless the user specifies a socket
968+ type other than {net.Socket}.
969+
942970Default behavior is to try close the socket with a HTTP '400 Bad Request',
943971or a HTTP '431 Request Header Fields Too Large' in the case of a
944972[ ` HPE_HEADER_OVERFLOW ` ] [ ] error. If the socket is not writable it is
@@ -983,13 +1011,17 @@ added: v0.7.0
9831011
9841012* ` request ` {http.IncomingMessage} Arguments for the HTTP request, as it is in
9851013 the [ ` 'request' ` ] [ ] event
986- * ` socket ` {net.Socket } Network socket between the server and client
1014+ * ` socket ` {stream.Duplex } Network socket between the server and client
9871015* ` head ` {Buffer} The first packet of the tunneling stream (may be empty)
9881016
9891017Emitted each time a client requests an HTTP ` CONNECT ` method. If this event is
9901018not listened for, then clients requesting a ` CONNECT ` method will have their
9911019connections closed.
9921020
1021+ This event is guaranteed to be passed an instance of the {net.Socket} class,
1022+ a subclass of {stream.Duplex}, unless the user specifies a socket
1023+ type other than {net.Socket}.
1024+
9931025After this event is emitted, the request's socket will not have a ` 'data' `
9941026event listener, meaning it will need to be bound in order to handle data
9951027sent to the server on that socket.
@@ -999,7 +1031,7 @@ sent to the server on that socket.
9991031added: v0.1.0
10001032-->
10011033
1002- * ` socket ` {net.Socket }
1034+ * ` socket ` {stream.Duplex }
10031035
10041036This event is emitted when a new TCP stream is established. ` socket ` is
10051037typically an object of type [ ` net.Socket ` ] [ ] . Usually users will not want to
@@ -1014,6 +1046,10 @@ If `socket.setTimeout()` is called here, the timeout will be replaced with
10141046` server.keepAliveTimeout ` when the socket has served a request (if
10151047` server.keepAliveTimeout ` is non-zero).
10161048
1049+ This event is guaranteed to be passed an instance of the {net.Socket} class,
1050+ a subclass of {stream.Duplex}, unless the user specifies a socket
1051+ type other than {net.Socket}.
1052+
10171053### Event: ` 'request' `
10181054<!-- YAML
10191055added: v0.1.0
@@ -1037,7 +1073,7 @@ changes:
10371073
10381074* ` request ` {http.IncomingMessage} Arguments for the HTTP request, as it is in
10391075 the [ ` 'request' ` ] [ ] event
1040- * ` socket ` {net.Socket } Network socket between the server and client
1076+ * ` socket ` {stream.Duplex } Network socket between the server and client
10411077* ` head ` {Buffer} The first packet of the upgraded stream (may be empty)
10421078
10431079Emitted each time a client requests an HTTP upgrade. Listening to this event
@@ -1047,6 +1083,10 @@ After this event is emitted, the request's socket will not have a `'data'`
10471083event listener, meaning it will need to be bound in order to handle data
10481084sent to the server on that socket.
10491085
1086+ This event is guaranteed to be passed an instance of the {net.Socket} class,
1087+ a subclass of {stream.Duplex}, unless the user specifies a socket
1088+ type other than {net.Socket}.
1089+
10501090### ` server.close([callback]) `
10511091<!-- YAML
10521092added: v0.1.90
@@ -1219,7 +1259,7 @@ will result in a [`TypeError`][] being thrown.
12191259added: v0.3.0
12201260-->
12211261
1222- * {net.Socket }
1262+ * {stream.Duplex }
12231263
12241264See [ ` response.socket ` ] [ ] .
12251265
@@ -1461,7 +1501,7 @@ timed out sockets must be handled explicitly.
14611501added: v0.3.0
14621502-->
14631503
1464- * {net.Socket }
1504+ * {stream.Duplex }
14651505
14661506Reference to the underlying socket. Usually users will not want to access
14671507this property. In particular, the socket will not emit ` 'readable' ` events
@@ -1478,6 +1518,10 @@ const server = http.createServer((req, res) => {
14781518}).listen (3000 );
14791519```
14801520
1521+ This property is guaranteed to be an instance of the {net.Socket} class,
1522+ a subclass of {stream.Duplex}, unless the user specified a socket
1523+ type other than {net.Socket}.
1524+
14811525### ` response.statusCode `
14821526<!-- YAML
14831527added: v0.4.0
@@ -1860,13 +1904,17 @@ Calls `message.connection.setTimeout(msecs, callback)`.
18601904added: v0.3.0
18611905-->
18621906
1863- * {net.Socket }
1907+ * {stream.Duplex }
18641908
18651909The [ ` net.Socket ` ] [ ] object associated with the connection.
18661910
18671911With HTTPS support, use [ ` request.socket.getPeerCertificate() ` ] [ ] to obtain the
18681912client's authentication details.
18691913
1914+ This property is guaranteed to be an instance of the {net.Socket} class,
1915+ a subclass of {stream.Duplex}, unless the user specified a socket
1916+ type other than {net.Socket}.
1917+
18701918### ` message.statusCode `
18711919<!-- YAML
18721920added: v0.1.1
0 commit comments