Skip to content

StaticFiles returns a 5xx when filenames are too long #2221

Answered by Kludex
etr2460 asked this question in Potential Issue
Discussion options

You must be logged in to vote

I don't think it should be a 4xx. 🤔

You can inherit StaticFiles, and change the get_response implementation:

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

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

Kludex
Jul 22, 2023
Maintainer Sponsor

You must be logged in to vote
0 replies
Answer selected by Kludex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants