-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. (As always, there's room for some more information to be added, but this is certainly better than not having it documented at all.)
I wonder if it might be possible to indicate a use case where a user might want to access these properties. Otherwise, readers may wonder about the statements that users usually won't want to access them. |
I think we should just document one of the two. At some point it'd be nice to remove one of them to have less duplication. Since core itself uses |
That's a great point. I was mostly just trying to address #12617, but to be honest I am having trouble thinking of an example where accessing the raw socket is required or advisable. Followed up on the issue to learn more. |
dismissing my review until mscdex suggestion sorted; I wouldn't stop anyone else from approving if they like this as-is, though
I went ahead and added the same documentation for @mscdex I agree that having both of these isn't ideal. I did some searching, and mostly found folks using For now, I went ahead and documented both, with |
Also, I added an example :) |
doc/api/http.md
Outdated
added: v0.3.0 | ||
--> | ||
|
||
* `connection` {net.Socket} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think the name (`connection`) is not needed here as this is property not a function argument.
doc/api/http.md
Outdated
```js | ||
const http = require('http'); | ||
http.createServer((req, res) => { | ||
const clientIp = req.socket.remoteAddress; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can you please use two spaces for indentation?
doc/api/http.md
Outdated
```js | ||
const http = require('http'); | ||
http.createServer((req, res) => { | ||
const clientIp = res.socket.remoteAddress; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
doc/api/http.md
Outdated
|
||
* `socket` {net.Socket} | ||
|
||
Reference to the underlying socket. `socket` is an object of type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to duplicate the type in a separate sentence if it is already specified above.
Thanks for the awesome feedback folks. All addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a couple of tiny nits. Thanks!
doc/api/http.md
Outdated
|
||
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()`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please wrap this line and the next one it at 80 characters?
doc/api/http.md
Outdated
|
||
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()`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits addressed
I think worthy cases to document would be |
0b02a9a
to
3019f16
Compare
Addressed all the things and rebased into one commit! |
doc/api/http.md
Outdated
@@ -497,6 +497,15 @@ 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.end([data[, encoding]][, callback]) | |||
### request.connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these supposed to be directly after each other?
doc/api/http.md
Outdated
const http = require('http'); | ||
http.createServer((req, res) => { | ||
const clientIp = req.socket.remoteAddress; | ||
res.end(`Your IP is ${clientIp}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to nitpick, but "IP address" would be more correct, as IP is just the protocol. Also, I'd add a second print for the port. Same goes for the res
example below.
Adds documentation and samples for the `connection` and `socket` properties available on the `http.serverResponse` and `http.clientRequest` objects. Fixes: nodejs#12617
One more try 😂 |
Thanks! Landed in d3d66a5. I also took the liberty to change |
Adds documentation and samples for the `connection` and `socket` properties available on the `http.serverResponse` and `http.clientRequest` objects. PR-URL: #13617 Fixes: #12617 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
@silverwind code does not lint 😢 Probably new lint rules added in #13645 |
P.S. we lint the JS in the snippets |
Argh, I forgot that we lint the docs. I was able to force-push a fix as the commit was still on |
Adds documentation and samples for the `connection` and `socket` properties available on the `http.serverResponse` and `http.clientRequest` objects. PR-URL: #13617 Fixes: #12617 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
Ugh. Per the collab guidelines: This force push happened 2 hours later. Please do not do that as it causes quite a bit of hassle for other devs. |
Yes, I'm aware of that rule. Just thought it's easier to backport as one commit later. What real harm does it cause when the replaced commit is still on HEAD? |
@silverwind The question is not really where the commit is in the history; the problem is more that people who update their clones from upstream now have a bogus |
I have four local branches and one open PR branch that I had rebased off master when I started today that I ended up having to go back and correct after the force push. Forcing outside of the 10 minute window ends up meaning other collaborators end up having to do extra work they really shouldn't have to do. |
Adds documentation and samples for the `connection` and `socket` properties available on the `http.serverResponse` and `http.clientRequest` objects. PR-URL: #13617 Fixes: #12617 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
Adds documentation and samples for the `connection` and `socket` properties available on the `http.serverResponse` and `http.clientRequest` objects. PR-URL: #13617 Fixes: #12617 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
Adds documentation and samples for the `connection` and `socket` properties available on the `http.serverResponse` and `http.clientRequest` objects. PR-URL: #13617 Fixes: #12617 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
Adds documentation and samples for the `connection` and `socket` properties available on the `http.serverResponse` and `http.clientRequest` objects. PR-URL: #13617 Fixes: #12617 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
Adds documentation for the
connection
andsocket
propertiesavailable on the
http.serverResponse
object.Fixes: #12617
Checklist
Affected core subsystem(s)