-
I used req from open handler to get the real client address in case of proxy.
but in latest version open handler is changed - req removed. How I could get proxied ip for websocket connection in this case? |
Beta Was this translation helpful? Give feedback.
Answered by
hst-m
Jun 30, 2020
Replies: 1 comment 1 reply
-
v18 removes you need to use the ws // pass values from ws upgrade handler
uws.App().ws('/', {
upgrade: (res, req, context) => { // request was made to open websocket, res req have all properties for request, cookies etc
// add code here to determine if ws request should be accepted or denied
// deny request with "res.writeStatus('401').end()" see issue #367
res.upgrade( // upgrade to websocket
{ ip: res.getRemoteAddressAsText() }, // 1st argument sets which properties to pass to ws object, in this case ip address
req.getHeader('sec-websocket-key'),
req.getHeader('sec-websocket-protocol'),
req.getHeader('sec-websocket-extensions'), // 3 headers are used to setup websocket
context // also used to setup websocket
)
},
open: ws => {
console.log(ws.ip)
}
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
v18 removes
req
from the ws open handler - v18.0.0docs - WebSocketBehavior.html#upgrade
docs - HttpResponse.html#upgrade
examples - Upgrade.js - UpgradeAsync.js
you need to use the ws
upgrade
handler to pass values from the original http request: