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

ws.upgradeReq is undefined #1114

Closed
Droppers opened this issue May 17, 2017 · 5 comments
Closed

ws.upgradeReq is undefined #1114

Droppers opened this issue May 17, 2017 · 5 comments

Comments

@Droppers
Copy link

Hello,

I am using the WS module, version 3.0.0. When I connect to the server I created, upgradeReq is undefined.

var url = ws.upgradeReq.url;
                           ^

TypeError: Cannot read property 'url' of undefined
    at Server.onWebSocketOpen (/home/admin/test/src/Server.js:626:28)
    at emitTwo (events.js:106:13)
    at WebSocketServer.emit (events.js:192:7)
    at handleUpgrade (/home/admin/test/node_modules/ws/lib/WebSocketServer.js:88:16)
    at WebSocketServer.completeUpgrade (/home/admin/test/node_modules/ws/lib/WebSocketServer.js:270:5)
    at WebSocketServer.handleUpgrade (/home/admin/test/node_modules/ws/lib/WebSocketServer.js:197:10)
    at Server.WebSocketServer._ultron.on (/home/admin/test/node_modules/ws/lib/WebSocketServer.js:87:14)
    at emitThree (events.js:116:13)
    at Server.emit (events.js:195:7)
    at onParserExecuteCommon (_http_server.js:462:14)

I am creating the server like this:

    var httpServer = http.createServer();

    this.wsServer = new this.WebSocket.Server({
        server: httpServer, 
        perMessageDeflate: false,
        maxPayload: 4096
    });
    this.wsServer.on('error', this.onWebSocketError.bind(this));
    this.wsServer.on('connection', this.onWebSocketOpen.bind(this));
    httpServer.listen(3000, '0.0.0.0', this.onHttpServerOpen.bind(this));

Maybe I am missing something?

@Droppers
Copy link
Author

Droppers commented May 17, 2017

Oh, I just noticed version 3.0.0 does not have upgradeReq anymore #1099.

That is really a major breaking change..

@lpinca
Copy link
Member

lpinca commented May 17, 2017

It's one of the breaking changes of version 3. See discussion in #1099 and release notes.

@Droppers
Copy link
Author

That is unfortunate, I will use version 2.3.1 then.

Thanks.

@lpinca
Copy link
Member

lpinca commented May 17, 2017

I'll reopen so ppl hopefully see this and don't open new issues for this.

@lpinca lpinca reopened this May 17, 2017
@lpinca
Copy link
Member

lpinca commented May 17, 2017

@Droppers in the definition of your onWebSocketOpen you can add the req object and you can upgrade to version 3 if you want.

Thing.prototype.onWebSocketOpen = function onWebSocketOpen(ws, req) {
  ws.upgradeReq = req;
  // ...
}

@lpinca lpinca closed this as completed May 21, 2017
acklenx added a commit to acklenx/node-http-mitm-proxy that referenced this issue Dec 11, 2017
an optimization in version 3.0 of the required proxy server [ websockets/ws#1114 ]drops the upgradeReq parameter to save 20% in memory.  This breaks non-http(s) requests that use upgrade to switch - like web sockets (ws and wss).  This was never a consideration for he mitm proxy (I guess since the package specifies version 3.2 and up - so it never worked).  This matters for me so we re include it per the recommendation from the package maintainers [ websockets/ws#1099 ]
0x17de referenced this issue in AndrewBelt/hack.chat Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants