-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
Allow for custom head method in HTTPEndpoint #1222
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -23,7 +23,15 @@ def __await__(self) -> typing.Generator: | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
async def dispatch(self) -> None: | ||||||||||||||||||||||||||||
request = Request(self.scope, receive=self.receive) | ||||||||||||||||||||||||||||
handler_name = "get" if request.method == "HEAD" else request.method.lower() | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if request.method == "HEAD": | ||||||||||||||||||||||||||||
if hasattr(self, "head"): | ||||||||||||||||||||||||||||
handler_name = "head" | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have test coverage for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. In which file would the relevant tests be? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really sure, maybe |
||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
handler_name = "get" | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
handler_name = request.method.lower() | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
Comment on lines
+26
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We just need to add the
Suggested change
|
||||||||||||||||||||||||||||
handler = getattr(self, handler_name, self.method_not_allowed) | ||||||||||||||||||||||||||||
is_async = asyncio.iscoroutinefunction(handler) | ||||||||||||||||||||||||||||
if is_async: | ||||||||||||||||||||||||||||
|
@@ -101,9 +109,7 @@ async def decode(self, websocket: WebSocket, message: Message) -> typing.Any: | |||||||||||||||||||||||||||
await websocket.close(code=status.WS_1003_UNSUPPORTED_DATA) | ||||||||||||||||||||||||||||
raise RuntimeError("Malformed JSON data received.") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
assert ( | ||||||||||||||||||||||||||||
self.encoding is None | ||||||||||||||||||||||||||||
), f"Unsupported 'encoding' attribute {self.encoding}" | ||||||||||||||||||||||||||||
assert self.encoding is None, f"Unsupported 'encoding' attribute {self.encoding}" | ||||||||||||||||||||||||||||
return message["text"] if message.get("text") else message["bytes"] | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
async def on_connect(self, websocket: WebSocket) -> None: | ||||||||||||||||||||||||||||
|
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.
It's safer to check
request.method.lower() == "head"