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
Bad handshake method (only when using extra headers!) #1140
Comments
Same Issue, here.. totally works with the nodejs version of socket.io-client though not the browser
|
Hi! I think you have to add the proper headers on the server-side (it seems you're in a CORS situation): const io = require('socket.io')(3000, {
handlePreflightRequest: function (req, res) {
var headers = {
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
'Access-Control-Allow-Origin': 'http://localhost:3001',
'Access-Control-Allow-Credentials': true
};
res.writeHead(200, headers);
res.end();
}
}); I added an example there: https://github.com/darrachequesne/socket.io-fiddle/tree/extra-headers |
@darrachequesne how to specify multiple domains for origin, following ways are not working:
|
@DaVincii i defined as null, but gets freed to any domain. const headers = { |
For CORS Use |
'Access-Control-Allow-Origin': req.headers.origin |
@supertiger1234 So in your case it should be:
|
|
How do I install the latest socket io? |
For future reference: this issue also occurs when using a post-3.0 server with a pre-3.0 client. This may be caused by a misconfigured cache that makes the clients use an older version of |
For future readers, please see:
|
You want to:
Current behaviour
I get a 400 with the message
{"code":2,"message":"Bad handshake method"}
when trying to connect my server with an extra header (works fine if i don't try to add it).Steps to reproduce (if the current behaviour is a bug)
I try to connect my server with the following configuration:
I also noticed that an OPTIONS request is made when i add this extra header (instead of a GET when i don't add it)
Expected behaviour
A get GET request (to preserve cookies) with the extra headers that don't break the handshake.
Setup
The text was updated successfully, but these errors were encountered: