diff --git a/doc/api/http.md b/doc/api/http.md index 6d8adbc1077d95..841f9b55492040 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -496,6 +496,15 @@ added: v0.11.14 If a request has been aborted, this value is the time when the request was aborted, in milliseconds since 1 January 1970 00:00:00 UTC. +### request.connection + + +* {net.Socket} + +See [`request.socket`][] + ### request.end([data[, encoding]][, callback]) + +* {net.Socket} + +Reference to the underlying socket. Usually users will not want to access +this property. In particular, the socket will not emit `'readable'` events +because of how the protocol parser attaches to the socket. After +`response.end()`, the property is nulled. The `socket` may also be accessed +via `request.connection`. + +Example: + +```js +const http = require('http'); +const server = http.createServer((req, res) => { + let clientIp = req.socket.remoteAddress; + let remotePort = req.socket.remotePort; + res.end(`Your IP is ${clientIp} and the remote port is ${remotePort}.`); +}).listen(3000); +``` + ### request.write(chunk[, encoding][, callback]) + +* {net.Socket} + +See [`response.socket`][]. + ### response.end([data][, encoding][, callback]) + +* {net.Socket} + +Reference to the underlying socket. Usually users will not want to access +this property. In particular, the socket will not emit `'readable'` events +because of how the protocol parser attaches to the socket. After +`response.end()`, the property is nulled. The `socket` may also be accessed +via `response.connection`. + +Example: + +```js +const http = require('http'); +const server = http.createServer((req, res) => { + let clientIp = res.socket.remoteAddress; + let remotePort = res.socket.remotePort; + res.end(`Your IP is ${clientIp} and the remote port is ${remotePort}.`); +}).listen(3000); +``` + ### response.statusCode