feat: automatically support HEAD method for all GET routes by jonathan-fulton · Pull Request #14792 · fastapi/fastapi
) Following HTTP semantics and Starlette's behavior, GET routes now automatically respond to HEAD requests. HEAD returns the same headers as GET but with an empty body. Changes: - Add HEAD to methods set when GET is present in APIRoute - Skip auto-added HEAD (when paired with GET) in OpenAPI schema generation - Update generate_unique_id to use deterministic method selection - Add comprehensive tests for HEAD method support This allows HEAD requests to work out of the box for cache validation and resource checks, without requiring developers to define explicit HEAD routes. Explicit HEAD routes still work when defined before GET routes. Fixes fastapi#1773