sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ability to intercept the websocket handshake

marinator86 opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe.

Thank you for this nice project!

In my websocket server, I need to initialize certain resources before a websocket connection handshake can be finished, i.e. I need to connect to a redis server. In a websocket-framework I previously used I could call an accept() method to finish the handshake from the server side manually. This made it easy for me to initialize those resources, and once everything was ready, I accepted the connection.

Describe the solution you'd like

Add a websocket.accept() method.

Additional context

No response

I think the best way to achieve this would be to isolate that websocket endpoint into its own Blueprint, and then add a on_request middleware attached to only that blueprint.

thank you, I wasn't aware about that