Repository navigation
StaticFiles 405 responses are missing the Allow header
#3634
Unanswered
sungbin1015
asked this question in
Potential Issue
Replies: 1 comment
|
you're right, it's missing. in staticfiles.py get_response raises a bare HTTPException(status_code=405) with no headers, while Route sets Allow from its methods. rfc 9110 says a 405 must include an Allow header so this looks like an oversight. fix would be headers={"Allow": "GET, HEAD"} on that raise. worth opening as an issue or PR if you want it fixed upstream. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
StaticFilesanswers non-GET/HEADrequests with405 Method Not Allowedbut without anAllowheader, whileRouteandHTTPEndpointinclude one.RFC 9110 §15.5.6 says the origin server MUST generate an
Allowheader in a 405 response. #1436 added it forRouteandHTTPEndpoint;StaticFilesraises its ownHTTPException(status_code=405)inget_responseand was not covered.Environment: Starlette
mainat ff5b4df, Python 3.11, Linux.The fix is one line (
headers={"Allow": "GET, HEAD"}) plus an assertion in the existingtest_staticfiles_post. I have it ready and will open a PR referencing this discussion; happy to adjust or drop it if you'd rather handle it differently.I searched open and closed issues, PRs and discussions for
StaticFiles+Allow/ 405 and found nothing covering it (#3585 is aboutHEADinHTTPEndpoint'sAllowvalue and only touchesendpoints.py).All reactions