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

WebSocket connection with query params - failed #14

Closed
grubberr opened this issue Sep 26, 2019 · 4 comments
Closed

WebSocket connection with query params - failed #14

grubberr opened this issue Sep 26, 2019 · 4 comments

Comments

@grubberr
Copy link
Contributor

Hello,

Thanks for your library but it seems it has some problems which has to be resolved

WebSocket URL with query params does not work

#!/usr/bin/env python3
  
import asyncio
from fastapi import FastAPI
from starlette.websockets import WebSocket
from async_asgi_testclient import TestClient

app = FastAPI()

url1 = '/ws' # works ok
url2 = '/ws?token=token'  # failed


@app.websocket_route('/ws')
async def websocket_endpoint(websocket: WebSocket):

    await websocket.accept()
    await websocket.send_text('Hello')


async def main():
    async with TestClient(app) as client:
        async with client.websocket_connect(url2) as websocket:
            print(await websocket.receive_text())

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
@grubberr
Copy link
Contributor Author

as I understand the problem, you build such scope

{'headers': [(b'host', b'localhost')],
 'path': '/ws?token=token',
 'query_string': b'',
 'root_path': '',
 'scheme': 'ws',
 'subprotocols': [],
 'type': 'websocket'}

but it has to be something like

{'headers': [(b'host', b'localhost')],
 'path': '/ws',
 'query_string': b'token=token',
 'root_path': '',
 'scheme': 'ws',
 'subprotocols': [],
 'type': 'websocket'}

@masipcat
Copy link
Contributor

masipcat commented Sep 26, 2019

Hello,

You are right. We forgot to add the parameter query_string in websocket_connect() (as in the regular open() method).

I encourage you to open a PR and fix it yourself, if you don't mind (I can help you with the fix if you need it).

Thank you!

@grubberr
Copy link
Contributor Author

I have created PR
#15
but use it please only as reference :)

@masipcat
Copy link
Contributor

Version 1.1.1 released

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