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

namespace is mixed up with query parameters #124

Closed
xuyaoqiang opened this issue Aug 1, 2017 · 7 comments
Closed

namespace is mixed up with query parameters #124

xuyaoqiang opened this issue Aug 1, 2017 · 7 comments
Labels

Comments

@xuyaoqiang
Copy link

I run an AsyncServer example with javascript client socket.io . But it will fail when client connect with query:

<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io('http://localhost:8000/test',{
	query:  {token: 'abc'}	
});
</script>

And server decode namespace as:

/test?token=abc

it seems like a bug of socket.io that encoded namesapce with query parameters; I wonder if I can push a compatible pr for this.

@miguelgrinberg
Copy link
Owner

I can't reproduce this problem here. I just added {query: {token: 'abc'}} as a second argument to the app.py examples (both the sanic and aiohttp versions), and in both cases the /test namespace works well.

Can you provide a complete example that reproduces the problem you are seeing, which includes both server and client code?

@xuyaoqiang
Copy link
Author

it's my mistake that I forgot mention about test environment, here is my setup:

  • OS: macos
  • browser: chrome 59
  • socket.io version: 2.0.3
  • python-socketio: master branch

And I'm using the Class-Based Namespaces feature.

This bug was introduced after socket-io.js@1.4.8, and it's still not fixed. Well, in fact, if you are using socketio-server and socketio-client together, it works fine because socketio-server reuse the code of socketio-client and the server urlparse the namespace.

here is my code:
https://github.com/xuyaoqiang/python-socketio/tree/invalid-namespace-example/examples/sanic

python3 app.py 

visit: http://localhost:8001

I set a breakpoint in function on_connect, and it's not working. If you could print log or set a breakpoint in method socketio.async_server. AsyncServer._handle_eio_message , you will find the namespace /test?token=abc .

@TheJKFever
Copy link

Yup, I'm having the same issue with flask-socketio not receiving the request when I use both query parameters and a namespace. Either one separately is fine, but the request is never received when I use both.

@miguelgrinberg
Copy link
Owner

@TheJKFever do you have code I can test here?

@TheJKFever
Copy link

TheJKFever commented Sep 14, 2017

I've got my server running on localhost:5000 with a @socketio.on("connect", namespace="/chat") endpoint.

On the client, this works for me:

var socket = io('http://localhost:5000/chat', {query: ""});

This does not:

var socket = io('http://localhost:5000/chat', {query: "anyquery=query"});

I'm using socketio 2.0.3 from https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js

@TheJKFever
Copy link

By the way, this was not resolved. I can reliably reproduce this issue. With query parameters, the socket will not connect on a namespace. The way I got around this was by not using namespacing at all, and just changing my endpoints to have the namespace in it like on('chat/some_endpoint', ... But this prevents me from being able to connect on a namespace (which I realized I don't really need).

@miguelgrinberg
Copy link
Owner

@TheJKFever This should be resolved now. I put in a fix yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants