StaticFiles returns a 5xx when filenames are too long #2221
Answered
by
Kludex
etr2460
asked this question in
Potential Issue
-
A filename that's too long causes an OSError, which StaticFiles doesn't catch and ends up as a 5xx. Ideally I think starlette should either:
|
Beta Was this translation helpful? Give feedback.
Answered by
Kludex
Jul 22, 2023
Replies: 2 comments
-
I've implemented the first solution mentioned here in #2222. Let me know if you think this is reasonable! |
Beta Was this translation helpful? Give feedback.
0 replies
-
I don't think it should be a 4xx. 🤔 You can inherit from starlette.exceptions import HTTPException
from starlette.staticfiles import StaticFiles
class NewStaticFiles(StaticFiles):
async def get_response(self, path: str, scope: Scope) -> Response:
try:
super().get_response(path, scope)
except OSError as exc:
raise HTTPException(status_code=400) from exc |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kludex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think it should be a 4xx. 🤔
You can inherit
StaticFiles
, and change theget_response
implementation: