html mode does not serve index #1806
-
Hiya, So I got a bug report in Starlite --> litestar-org/litestar#354. Testing this out it appears that Starlette does not serve index.html in html=True mode, because stat_result is empty. The documentation state:
See: https://www.starlette.io/staticfiles/ Yet, the actual code is: if stat_result and stat.S_ISREG(stat_result.st_mode):
# We have a static file to serve.
return self.file_response(full_path, stat_result, scope)
elif stat_result and stat.S_ISDIR(stat_result.st_mode) and self.html:
# We're in HTML mode, and have got a directory URL.
# Check if we have 'index.html' file to serve.
index_path = os.path.join(path, "index.html")
full_path, stat_result = await anyio.to_thread.run_sync(
self.lookup_path, index_path
)
if stat_result is not None and stat.S_ISREG(stat_result.st_mode):
if not scope["path"].endswith("/"):
# Directory URLs should redirect to always end in "/".
url = URL(scope=scope)
url = url.replace(path=url.path + "/")
return RedirectResponse(url=url)
return self.file_response(full_path, stat_result, scope)
if self.html:
# Check for '404.html' if we're in HTML mode.
full_path, stat_result = await anyio.to_thread.run_sync(
self.lookup_path, "404.html"
)
if stat_result and stat.S_ISREG(stat_result.st_mode):
return FileResponse(
full_path,
stat_result=stat_result,
method=scope["method"],
status_code=404,
) Note that the call to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I cannot reproduce what the report says... https://github.com/Kludex/starlette-bug-1808 |
Beta Was this translation helpful? Give feedback.
I cannot reproduce what the report says... https://github.com/Kludex/starlette-bug-1808