Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

theblazehen
Copy link
Contributor

Fix for #1221


if request.method == "HEAD":
if hasattr(self, "head"):
handler_name = "head"
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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":
Copy link
Member

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"

Copy link
Member

@Kludex Kludex left a 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?

Comment on lines +26 to +34

if request.method == "HEAD":
if hasattr(self, "head"):
handler_name = "head"
else:
handler_name = "get"
else:
handler_name = request.method.lower()

Copy link
Member

@Kludex Kludex Sep 25, 2021

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.

Suggested change
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()
)

@Kludex
Copy link
Member

Kludex commented Nov 23, 2021

@theblazehen Do you wish to resume your work? Otherwise, I'll be closing as stale 😗

@Kludex
Copy link
Member

Kludex commented Nov 27, 2021

Close in favor of #1346

@Kludex Kludex closed this Nov 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants