Why is the remote address hiding?

I am using Node.js with https://github.com/websockets/ws .

I am trying to save remoteAddress users in a temporary socket variable. I can access this variable: socket.upgradeReq.connection.remoteAddress

The problem is, where did remoteAddress come from in the world? The variable "remoteAddress" was not even found in any of the WS node_plugin files in the lib directory. (I used Notepad ++ to search each file.)

The only reason I came to find access to this variable is the topic: How to get client IP address using websocket (einaros / ws) lib in Node.js?

Damn, even when displaying console.log(self.upgradeReq.connection); in my console I still can not find it!

Pictures of the list of console objects:

Enter image description here

Enter image description here

Where in the world? Did I miss something?

+5
source share
1 answer

Includes Node.js module, built-in net . Here's how to track it:

The ws documentation refers to upgradeReq as "the HTTP request that initiated the upgrade." Looking through the ws code makes it clear that Node.js uses the http built-in library to process HTTP requests.

The Node.js http documentation says that http.ClientRequest.connection is a link to this request, which is the basis of TCP socket .

Node.js The TCP code is in the net library. net docs document socket.remoteAddress .

+3
source

Source: https://habr.com/ru/post/1214406/


All Articles