-
-
Notifications
You must be signed in to change notification settings - Fork 931
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
Conversation
|
||
if request.method == "HEAD": | ||
if hasattr(self, "head"): | ||
handler_name = "head" |
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.
Do you have test coverage for this?
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.
No. In which file would the relevant tests be?
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.
Not really sure, maybe tests/test_endpoints.py
. Or any other places using HTTPEndpoint
@@ -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": |
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"
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.
@theblazehen Thanks for the PR! 🎉
Can you rebase it and check my comment?
|
||
if request.method == "HEAD": | ||
if hasattr(self, "head"): | ||
handler_name = "head" | ||
else: | ||
handler_name = "get" | ||
else: | ||
handler_name = request.method.lower() | ||
|
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.
We just need to add the not hasattr(self, "head")
logic.
if request.method == "HEAD": | |
if hasattr(self, "head"): | |
handler_name = "head" | |
else: | |
handler_name = "get" | |
else: | |
handler_name = request.method.lower() | |
handler_name = ( | |
"get" | |
if request.method == "HEAD" and not hasattr(self, "head") | |
else request.method.lower() | |
) |
@theblazehen Do you wish to resume your work? Otherwise, I'll be closing as stale 😗 |
Close in favor of #1346 |
Fix for #1221