fastapi/fastapi
Jonathan Fulton d201fdcdfa feat: automatically support HEAD method for all GET routes (#1773)
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 #1773
2026-01-31 19:14:13 -05:00
..
_compat Drop support for `pydantic.v1` (#14609) 2025-12-27 13:54:56 +01:00
dependencies Drop support for `pydantic.v1` (#14609) 2025-12-27 13:54:56 +01:00
middleware 🐛 Fix support for `StreamingResponse`s with dependencies with `yield` or `UploadFile`s, close after the response is done (#14099) 2025-09-29 05:29:38 +02:00
openapi feat: automatically support HEAD method for all GET routes (#1773) 2026-01-31 19:14:13 -05:00
security ♻️ Upgrade internal syntax to Python 3.9+ 🎉 (#14564) 2025-12-17 21:25:59 +00:00
__init__.py 🔖 Release version 0.128.0 2025-12-27 16:19:50 +01:00
__main__.py ♻️ Add support for `pip install "fastapi[standard]"` with standard dependencies and `python -m fastapi` (#11935) 2024-08-02 01:03:05 -05:00
applications.py ♻️ Upgrade internal syntax to Python 3.9+ 🎉 (#14564) 2025-12-17 21:25:59 +00:00
background.py ♻️ Upgrade internal syntax to Python 3.9+ 🎉 (#14564) 2025-12-17 21:25:59 +00:00
cli.py ♻️ Add support for `pip install "fastapi[standard]"` with standard dependencies and `python -m fastapi` (#11935) 2024-08-02 01:03:05 -05:00
concurrency.py ♻️ Upgrade internal syntax to Python 3.9+ 🎉 (#14564) 2025-12-17 21:25:59 +00:00
datastructures.py Drop support for `pydantic.v1` (#14609) 2025-12-27 13:54:56 +01:00
encoders.py Drop support for `pydantic.v1` (#14609) 2025-12-27 13:54:56 +01:00
exception_handlers.py ⬆️ Upgrade Starlette supported version range to >=0.40.0,<0.49.0 (#14077) 2025-09-16 19:21:48 +02:00
exceptions.py Drop support for `pydantic.v1` (#14609) 2025-12-27 13:54:56 +01:00
logger.py 🔊 Refactor logging (#781) 2019-12-09 20:02:44 +01:00
param_functions.py Drop support for `pydantic.v1` (#14609) 2025-12-27 13:54:56 +01:00
params.py Drop support for `pydantic.v1` (#14609) 2025-12-27 13:54:56 +01:00
py.typed add py.typed to ship typing information (#209) 2019-05-11 13:43:47 +04:00
requests.py ⬆ Require Pydantic > 1.0 (#1862) 2020-08-09 22:17:08 +02:00
responses.py Add reference (code API) docs with PEP 727, add subclass with custom docstrings for `BackgroundTasks`, refactor docs structure (#10392) 2023-10-18 16:36:40 +04:00
routing.py feat: automatically support HEAD method for all GET routes (#1773) 2026-01-31 19:14:13 -05:00
staticfiles.py Improve type annotations, add support for mypy --strict, internally and for external packages (#2547) 2020-12-20 19:50:00 +01:00
templating.py Improve type annotations, add support for mypy --strict, internally and for external packages (#2547) 2020-12-20 19:50:00 +01:00
testclient.py Improve type annotations, add support for mypy --strict, internally and for external packages (#2547) 2020-12-20 19:50:00 +01:00
types.py ♻️ Upgrade internal syntax to Python 3.9+ 🎉 (#14564) 2025-12-17 21:25:59 +00:00
utils.py feat: automatically support HEAD method for all GET routes (#1773) 2026-01-31 19:14:13 -05:00
websockets.py Export `WebSocketState` in `fastapi.websockets` (#4376) 2022-09-04 17:12:10 +02:00