Skip to content

Commit

Permalink
Allow head method httpendpoint (#1346)
Browse files Browse the repository at this point in the history
* Allow for custom head method in HTTPEndpoint

Fix for #1221

* Fix formatting

* Allow custom head method in HTTPEndpoint

Co-authored-by: theblazehen <theblazehen@gmail.com>
  • Loading branch information
Kludex and theblazehen committed Nov 27, 2021
1 parent 0220088 commit 82b75f7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion starlette/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ 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()
handler_name = (
"get"
if request.method == "HEAD" and not hasattr(self, "head")
else request.method.lower()
)

handler = getattr(self, handler_name, self.method_not_allowed)
is_async = asyncio.iscoroutinefunction(handler)
if is_async:
Expand Down

0 comments on commit 82b75f7

Please sign in to comment.