Giter Club home page Giter Club logo

Comments (4)

holesch avatar holesch commented on August 11, 2024 1

So I looked into it a bit more: Since asgineer uses the ASGI abstraction, it's not as easy as just sending an HTTP response (I should've thought about that).

Here's what's possible with ASGI using the websocket.close message:

If this is sent before the socket is accepted, the server must close the connection with a HTTP 403 error code (Forbidden), and not complete the WebSocket handshake; [...]

Changing the HTTP status code is not possible, but there's the Websocket Denial Response ASGI extension for that. It also states the reason why this is just an extension:

Rather than being a core part of ASGI, this is an extension for what is considered a niche feature as most clients do not utilise the denial response.

Uvicorn doesn't support this extension and it hasn't been decided if it ever will support it. A discussion for adding Websocket Denial Response to Uvicorn was started.

Regarding my specific issue: I'm fine with using request.close() and sending the 403, even if it's not the "correct" one.

from asgineer.

almarklein avatar almarklein commented on August 11, 2024

It's been a while since I looked into the low-level details of websockets, but I don't think you can simply return a plain result. We could add a request.deny() though, or something along that line. Have you looked at other related libs do/support this?

from asgineer.

holesch avatar holesch commented on August 11, 2024

As long as you don't accept the connection, it's still just an HTTP request, so you can send an HTTP response with a plain text error message. websockets actually has such a method as you suggested: ServerConnection.reject().

I thought about subclassing HttpRequest, instead of BaseRequest, but that's probably overkill.

So .deny()/.reject() sounds good to me. Let me know if I should work on it. I might find some time next week.

from asgineer.

almarklein avatar almarklein commented on August 11, 2024

Thanks for the detailed feedback! Yeah, being able to deny the connection in a more appropriate way would have been nice ...

from asgineer.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.