Include 'Allow' header on default 405 Method Not Allowed responses #6505
-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI
from fastapi.testclient import TestClient
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
client = TestClient(app)
def test_method_not_allowed_has_allow_headers():
response = client.put("/")
assert response.status_code == 405, response.status_code
assert "allow" in response.headers, response.headersDescriptionA 405 Method Not Allowed response should include an 'Allow' header indicating what mehtods are allowed (ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405) Wanted SolutionThe 'allow' header should be included with a list of allowed methods Wanted Codefrom fastapi import FastAPI
from fastapi.testclient import TestClient
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
client = TestClient(app)
def test_method_not_allowed_has_allow_headers():
response = client.put("/")
assert response.status_code == 405, response.status_code
assert "allow" in response.headers, response.headers
assert response.headers["allow"] == "GET, HEAD"AlternativesNo response Operating SystemLinux Operating System DetailsNo response FastAPI Version0.70.1 Python VersionPython 3.9.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
We'll handle this on Starlette's side. Thanks for the issue. |
Beta Was this translation helpful? Give feedback.
-
|
It will be available on the next Starlette release, and consequently in some FastAPI. Related PR: Kludex/starlette#1436 |
Beta Was this translation helpful? Give feedback.
-
|
Fixed on Starlette side ⚡ |
Beta Was this translation helpful? Give feedback.
It will be available on the next Starlette release, and consequently in some FastAPI.
Related PR: Kludex/starlette#1436