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

Support Websocket Denial Response #2436

Open
CaselIT opened this issue Feb 27, 2025 · 3 comments
Open

Support Websocket Denial Response #2436

CaselIT opened this issue Feb 27, 2025 · 3 comments

Comments

@CaselIT
Copy link
Member

CaselIT commented Feb 27, 2025

This is an extension that allows sending a custom http response over websocket, to deny the upgrade from http to websocket. It's defined here: https://asgi.readthedocs.io/en/latest/extensions.html#websocket-denial-response

It can be sent only before accepting a websocket connection.

The api could be something like

class WebSocket:
  ...

  async def deny(self,
    status, *, headers=None, body: bytes|str=None
  ) -> None: ...

Not sure if it makes sense allowing media here, since websocket has no concept of mime type etc, so it's likely fine to just require that the body is already serialized

as for supporting asgi framework, uvicorn does support it https://www.uvicorn.org/release-notes/#added_8

@vytas7
Copy link
Member

vytas7 commented Mar 1, 2025

Maybe an MVP could be to add support for this thing in the error handling, so that HTTP errors would be serialized using the correct code and headers. We would probably still need a synthetic resp object though 🤔

@vytas7 vytas7 added this to the Version 4.x milestone Mar 1, 2025
@CaselIT
Copy link
Member Author

CaselIT commented Mar 1, 2025

We would probably still need a synthetic resp object though

I don't follow why we would need that? deny() would be similar to close() as it's a use once method

@vytas7
Copy link
Member

vytas7 commented Mar 1, 2025

I meant that ideally we would like to automatically handle this for HTTPError and HTTPStatus, then we might need a resp (but it is easy to create one). A simple deny() does not need it indeed.

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

No branches or pull requests

2 participants