diff --git a/doc/api/http.md b/doc/api/http.md index 40715d5f33..8558900d88 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -74,9 +74,9 @@ to keep the Node.js process running when there are no outstanding requests. It is good practice, to [`destroy()`][] an `Agent` instance when it is no longer in use, because unused sockets consume OS resources. -Sockets are removed from an agent's pool when the socket emits either +Sockets are removed from an agent when the socket emits either a `'close'` event or an `'agentRemove'` event. When intending to keep one -HTTP request open for a long time without keeping it in the pool, something +HTTP request open for a long time without keeping it in the agent, something like the following may be done: ```js @@ -168,8 +168,9 @@ Called when `socket` is detached from a request and could be persisted by the Agent. Default behavior is to: ```js +socket.setKeepAlive(true, this.keepAliveMsecs); socket.unref(); -socket.setKeepAlive(agent.keepAliveMsecs); +return true; ``` This method can be overridden by a particular `Agent` subclass. If this @@ -226,13 +227,14 @@ added: v0.11.4 * `port` {number} Port of remote server * `localAddress` {string} Local interface to bind for network connections when issuing the request + * `family` {integer} Must be 4 or 6 if this doesn't equal `undefined`. * Returns: {string} Get a unique name for a set of request options, to determine whether a -connection can be reused. For an HTTP agent, this returns -`host:port:localAddress`. For an HTTPS agent, the name includes the -CA, cert, ciphers, and other HTTPS/TLS-specific options that determine -socket reusability. +connection can be reused. For an HTTP agent, this returns +`host:port:localAddress` or `host:port:localAddress:family`. For an HTTPS agent, +the name includes the CA, cert, ciphers, and other HTTPS/TLS-specific options +that determine socket reusability. ### agent.maxFreeSockets -* `request` {http.ClientRequest} +* `request` {http.IncomingMessage} * `response` {http.ServerResponse} Emitted each time a request with an HTTP `Expect` header is received, where the @@ -1224,8 +1231,8 @@ Example: ```js const http = require('http'); const server = http.createServer((req, res) => { - const ip = req.socket.remoteAddress; - const port = req.socket.remotePort; + const ip = res.socket.remoteAddress; + const port = res.socket.remotePort; res.end(`Your IP address is ${ip} and your source port is ${port}.`); }).listen(3000); ``` @@ -1883,6 +1890,7 @@ const req = http.request(options, (res) => { [`TypeError`]: errors.html#errors_class_typeerror [`URL`]: url.html#url_the_whatwg_url_api [`agent.createConnection()`]: #http_agent_createconnection_options_callback +[`agent.getName()`]: #http_agent_getname_options [`destroy()`]: #http_agent_destroy [`http.Agent`]: #http_class_http_agent [`http.ClientRequest`]: #http_class_http_clientrequest @@ -1898,6 +1906,7 @@ const req = http.request(options, (res) => { [`net.Server`]: net.html#net_class_net_server [`net.Socket`]: net.html#net_class_net_socket [`net.createConnection()`]: net.html#net_net_createconnection_options_connectlistener +[`request.end()`]: #http_request_end_data_encoding_callback [`request.socket`]: #http_request_socket [`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed [`request.write(data, encoding)`]: #http_request_write_chunk_encoding_callback