Making static route more verbose if file not found (#1945)

Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
This commit is contained in:
Tomasz Drożdż
2020-12-28 22:17:32 +01:00
committed by GitHub
parent 449bc417a3
commit 7475897a03

View File

@@ -13,6 +13,7 @@ from sanic.exceptions import (
InvalidUsage,
)
from sanic.handlers import ContentRangeHandler
from sanic.log import error_logger
from sanic.response import HTTPResponse, file, file_stream
@@ -40,6 +41,10 @@ async def _static_request_handler(
# match filenames which got encoded (filenames with spaces etc)
file_path = path.abspath(unquote(file_path))
if not file_path.startswith(path.abspath(unquote(root_path))):
error_logger.exception(
f"File not found: path={file_or_directory}, "
f"relative_url={file_uri}"
)
raise FileNotFound(
"File not found", path=file_or_directory, relative_url=file_uri
)
@@ -94,6 +99,10 @@ async def _static_request_handler(
except ContentRangeError:
raise
except Exception:
error_logger.exception(
f"File not found: path={file_or_directory}, "
f"relative_url={file_uri}"
)
raise FileNotFound(
"File not found", path=file_or_directory, relative_url=file_uri
)