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
Send HTTP 400 response for invalid request #1352
Conversation
Given an invalid request, respond with an HTTP 400 error instead of closing the connection without a response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible for both implementations of send_400_response
to have the same signature ? one take str the other bytes.
or maybe there's a good reason
Yes, would be possible. What would be the preferred datatype? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @bertramr
from uvicorn.protocols.websockets.auto import AutoWebSocketsProtocol | ||
|
||
if AutoWebSocketsProtocol is None: | ||
msg = "No supported WebSocket library detected. Please use 'pip install uvicorn[standard]', or install 'websockets' or 'wsproto' manually." # noqa: E501 | ||
self.logger.warning(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it needs to be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was part of improving user experience in #926 @tomchristie
Do you want we get rid of it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it just needs to stay within the if upgrade_value != b"websocket" or self.ws_protocol_class is None:
block. It doesn't make sense for this to be within send_400_response
right? (Eg. it shouldn't log if it's called because of except httptools.HttpParserError as exc:
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha yes you're right I didn't notice if was sent also in that case, I misread thinking it was just for the upgrade case
from uvicorn.protocols.websockets.auto import AutoWebSocketsProtocol | ||
|
||
if AutoWebSocketsProtocol is None: | ||
msg = "No supported WebSocket library detected. Please use 'pip install uvicorn[standard]', or install 'websockets' or 'wsproto' manually." # noqa: E501 | ||
self.logger.warning(msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it needs to be deleted.
* Send HTTP 400 response for invalid request Given an invalid request, respond with an HTTP 400 error instead of closing the connection without a response. * changed signature of send_400_response to msg as str Co-authored-by: Mark Breedlove <mb@dp.la>
Given an invalid request, respond with an HTTP 400 error instead of
closing the connection without a response.
Please find here a rebased version of #205