Comments (4)
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.
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.
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.
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)
- More robust capuring of stdout/stderr in steams HOT 1
- RTD
- What would a websocket API look like? HOT 1
- Websocket refinement and tests HOT 1
- Can we do without a response class?
- Rename handler2asgi? HOT 2
- Raise EOFError instead of IOError upon connection/ws close
- 100% coverage
- Type hints
- Common utilities HOT 1
- Change cleanup to shutdown in lifetime messages
- Support for 3d party middleware HOT 5
- Use of request.host HOT 1
- Make use of ASGI 3.0
- Dont compress files that already are
- Use streaming for video and gif HOT 1
- Asset handler should not return a body for HEAD requests.
- "304 Not Modified" is returning the wrong headers HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asgineer.