Skip to content

req removed from ws open handler #339

Answered by hst-m
acharkov asked this question in Q&A
Discussion options

You must be logged in to vote

v18 removes req from the ws open handler - v18.0.0
docs - 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:

// 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 se…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@wengjianhong
Comment options

Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #339 on December 09, 2020 03:28.