From b141423b13882e848b484367095ff9d47d9aa9de Mon Sep 17 00:00:00 2001 From: Herrtian <70463940+Herrtian@users.noreply.github.com> Date: Sun, 14 Jun 2026 15:12:25 +0200 Subject: [PATCH] fix: handle routes without methods in head helper --- fastapi/routing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastapi/routing.py b/fastapi/routing.py index 39a78f11db..2520e3a6e5 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -1157,10 +1157,11 @@ class APIRoute(routing.Route): ) -> bool: """Check if this is a HEAD request that should be served by a GET route.""" route_methods = methods if methods is not None else self.methods + if not route_methods: + return False return ( scope.get("type") == "http" and scope.get("method") == "HEAD" - and bool(route_methods) and "GET" in route_methods and "HEAD" not in route_methods )