Skip to content

Allow for custom head method in HTTPEndpoint#1222

Closed
theblazehen wants to merge 3 commits intoKludex:masterfrom
theblazehen:patch-1
Closed

Allow for custom head method in HTTPEndpoint#1222
theblazehen wants to merge 3 commits intoKludex:masterfrom
theblazehen:patch-1

Conversation

@theblazehen
Copy link
Copy Markdown
Contributor

Fix for #1221


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

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
Copy Markdown
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
Copy Markdown
Contributor

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

request = Request(self.scope, receive=self.receive)
handler_name = "get" if request.method == "HEAD" else request.method.lower()

if request.method == "HEAD":
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Owner

@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
Copy Markdown
Owner

@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
Copy Markdown
Owner

Kludex commented Nov 23, 2021

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

@Kludex
Copy link
Copy Markdown
Owner

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