-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
handleUpgrade() and undefined upgrade header #1838
Comments
It can only happen if the httpServer.on('upgrade', function (req, socket, head) {
// Here `req.headers.upgrade` cannot be `undefined`, otherwise there is a bug in Node.js.
wss.handleUpgrade(req, socket, head, callback);
}); |
Please fill the issue template, it's there for a reason. Also, if you can, please write a test case using only |
Sorry for that, I created the issue from the code view (Reference in new issue), no model was requested. |
In fact I am using
Everything seems to work properly except for non-ws requests (that is expected of course) |
Yes, you can't do that, it doesn't make sense. The HTTP parser is still attached to the I would even say that the thrown error is good in that case. |
Thanks, however, I don't understand properly why it can't work (at least with upgrade requests only)
|
Because upgrade requests are used to upgrade to another protocol not HTTP and are handled differently by Node.js. When you use httpServer.on('request', function (req, res) {}); Upgrade requests are handled with httpServer.on('upgrade', function (req, socket, head) {}); and the socket in this case is freed. In your example the socket is still piped to the HTTP parser so it might not work if the client writes something using a different protocol. Also there is no reason to keep the HTTP parser and the |
ok I see, thanks ! |
I'm closing this as answered. Discussion can continue if needed. |
ws/lib/websocket-server.js
Line 193 in 2789887
req.headers.upgrade
may be undefined, that will raiseTypeError: Cannot read property 'toLowerCase' of undefined
The text was updated successfully, but these errors were encountered: