From 24ecc331e2e65403231358f61a9794885323e8eb Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Sun, 11 Jun 2017 11:18:03 -0700 Subject: [PATCH] doc: document res.connection and res.socket Adds documentation and samples for the `connection` and `socket` properties available on the `http.serverResponse` and `http.clientRequest` objects. PR-URL: https://github.com/nodejs/node/pull/13617 Fixes: https://github.com/nodejs/node/issues/12617 Reviewed-By: Roman Reiss Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Alexey Orlenko --- doc/api/http.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/doc/api/http.md b/doc/api/http.md index 6d8adbc107..66ea4e7631 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) => { + const ip = req.socket.remoteAddress; + const port = req.socket.remotePort; + res.end(`Your IP address is ${ip} and your source port is ${port}.`); +}).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) => { + const ip = req.socket.remoteAddress; + const port = req.socket.remotePort; + res.end(`Your IP address is ${ip} and your source port is ${port}.`); +}).listen(3000); +``` + ### response.statusCode