Skip to content

Commit 32ee718

Browse files
committed
fix(http): allow HEAD on root redirect
1 parent fe87e39 commit 32ee718

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
app.add_exception_handler(RequestValidationError, validation_exception_handler)
2424

2525

26-
@app.get("/", include_in_schema=False)
26+
@app.api_route("/", methods=["GET", "HEAD"], include_in_schema=False)
2727
async def root_redirect() -> RedirectResponse:
2828
return RedirectResponse(url="/docs", status_code=307)

tests/test_root.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ async def test_root_redirects_to_docs(async_client: httpx.AsyncClient) -> None:
88
response = await async_client.get("/", follow_redirects=False)
99
assert response.status_code in (302, 307)
1010
assert response.headers.get("location") == "/docs"
11+
12+
13+
async def test_head_root_redirects_to_docs(async_client: httpx.AsyncClient) -> None:
14+
response = await async_client.head("/", follow_redirects=False)
15+
assert response.status_code in (302, 307)
16+
assert response.headers.get("location") == "/docs"

0 commit comments

Comments
 (0)