Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: document res.connection and res.socket #13617

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<!-- YAML
added: v0.3.0
-->

* {net.Socket}

See [`request.socket`][]

### request.end([data[, encoding]][, callback])
<!-- YAML
added: v0.1.90
Expand Down Expand Up @@ -564,6 +573,30 @@ Once a socket is assigned to this request and is connected

Returns `request`.

### request.socket
<!-- YAML
added: v0.3.0
-->

* {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])
<!-- YAML
added: v0.1.29
Expand Down Expand Up @@ -955,6 +988,16 @@ response.end();
Attempting to set a header field name or value that contains invalid characters
will result in a [`TypeError`][] being thrown.


### response.connection
<!-- YAML
added: v0.3.0
-->

* {net.Socket}

See [`response.socket`][].

### response.end([data][, encoding][, callback])
<!-- YAML
added: v0.1.90
Expand Down Expand Up @@ -1163,6 +1206,30 @@ timed out sockets must be handled explicitly.

Returns `response`.

### response.socket
<!-- YAML
added: v0.3.0
-->

* {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
<!-- YAML
added: v0.4.0
Expand Down Expand Up @@ -1831,9 +1898,11 @@ 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.socket`]: #http_request_socket
[`request.socket.getPeerCertificate()`]: tls.html#tls_tlssocket_getpeercertificate_detailed
[`response.end()`]: #http_response_end_data_encoding_callback
[`response.setHeader()`]: #http_response_setheader_name_value
[`response.socket`]: #http_response_socket
[`response.write()`]: #http_response_write_chunk_encoding_callback
[`response.write(data, encoding)`]: #http_response_write_chunk_encoding_callback
[`response.writeContinue()`]: #http_response_writecontinue
Expand Down