]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Allow head method httpendpoint (#1346)
authorMarcelo Trylesinski <marcelotryle@gmail.com>
Sat, 27 Nov 2021 17:40:57 +0000 (18:40 +0100)
committerGitHub <noreply@github.com>
Sat, 27 Nov 2021 17:40:57 +0000 (18:40 +0100)
* Allow for custom head method in HTTPEndpoint

Fix for https://github.com/encode/starlette/issues/1221

* Fix formatting

* Allow custom head method in HTTPEndpoint

Co-authored-by: theblazehen <theblazehen@gmail.com>
starlette/endpoints.py

index 2504dd84dd63fb1e569fbea19e4b3d0786ac7575..e0b7be8dea0415b7422b64046a218ac757b8f112 100644 (file)
@@ -23,7 +23,12 @@ class HTTPEndpoint:
 
     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: