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

Use req.socket instead of req.connection #8 #9

Closed

Conversation

briceruzand
Copy link

@al-bglhk
Copy link

al-bglhk commented Jan 8, 2021

Thank you for the fix! I am hitting the same warning from the logs. When will this fix be released?

@mcollina
Copy link

mcollina commented Feb 5, 2021

FIY: req.connection is deprecated in Node.js core. https://nodejs.org/api/http.html#http_request_connection
req.socket has been there since 0.3

@dougwilson
Copy link
Contributor

Thanks for this PR, and sorry I was not subscribed to this module's notifications.

I see no issue with reading the new property, but I am a little afraid about modules on npm that are trying to overwrite the ip or mock http may end up having an issue once this is merged.

I am thinking about the impact to the use in Express, so it may extend to other things using this.

So I'm wondering if it would be possible to keep reading both values or something. I will try to research into what the mocks and such are doing at least in the Express ecosystem to assess the impact of switching to a new property, but anyone is welcome to post an assessment as well.

No assessment on the impact has been provided so far, so I will try to do it this weekend since Node.js has deprecated the property used here (though I'm not sure what the impact of using the old property is).

@dougwilson dougwilson added the pr label Feb 13, 2021
@dougwilson
Copy link
Contributor

Just as an update before I go to sleep, I looked around a bit, and there are definately a fair number of mock libraries on public npm that only provide a req.socket and no req.connection. Of course, as well as a lot of test suites on public github not using a mock library. Here is a specific mock module that does not seem compatible with this change: https://www.npmjs.com/package/node-mocks-http (note: this is not comprehensive, as I haven't looked for very long).

So ideally if there is a way to make this change backwards-compatible that would be amazing.

If it is not possible, then we may want to figure out what our next steps should be.

Anyway, the above can still be deferred until there is a more comprehensive list of affected mock libraries, etc. as well.

@dougwilson
Copy link
Contributor

Sorry, I just realized before I signed off, that I... swapped req.socket and req.connection in my mind :( I was looking for the wrong property, haha. So I guess I didn't actually even start on looking, doh! I will look tomorrow for the correct property...

Copy link

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - proxy-addr tests only mock .connection. I think we should release this as patch, so the best option is to support both.

@@ -28,7 +28,7 @@ function forwarded (req) {

// simple header parsing
var proxyAddrs = parse(req.headers['x-forwarded-for'] || '')
var socketAddr = req.connection.remoteAddress
var socketAddr = req.socket.remoteAddress

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var socketAddr = req.socket.remoteAddress
var socketAddr = req.socket ? req.socket.remoteAddress : req.connection.remoteAddress

A test should be added to cover this case.

@dougwilson
Copy link
Contributor

Hi @briceruzand I went ahead and incorporated all the changes from this PR as well as added tests for these changes since I didn't hear any objection about the changes, but also the changes were never accepted in to the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

req.connection is deprecated
4 participants