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 conflicts with http GET #70

Open
Tronic opened this issue Jan 31, 2023 · 0 comments
Open

Websocket conflicts with http GET #70

Tronic opened this issue Jan 31, 2023 · 0 comments

Comments

@Tronic
Copy link
Member

Tronic commented Jan 31, 2023

I find it a bit surprising that a websocket request to Sanic ends up in an app.get handler (at least with the http1 server - didn't try asgi), as to my knowledge Sanic does not provide means to handle such requests in any meaningful way (you could respond 101 perhaps but then what?), and if you simply ignore the header, the connection will fail but your handler runs for nothing.

Also, it is not possible to serve GET and websocket (GET+Upgrade) at the same path like so:

@app.get("/")
def index(req):
    ...

@app.websocket("/")
def websocket(req, ws):
    ...

Would it be possible to change the routing such that upgrade: websocket requests are considered a different method than GET, or alternatively make the scheme also a part of routing (ws, wss, http and https each being different routing-wise)?

On the front side the same path as the document is convenient:

// Same path (easy peasy)
const ws = new WebSocket(location.href.replace(/^http/, 'ws'))

// Different path
const ws_path = '/ws'  // sometimes hard to know in front code
const ws = new WebSocket(new URL(ws_path, location.href.replace(/^http/, 'ws')))
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

1 participant