Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion shiny/http_staticfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from __future__ import annotations

import re

__all__ = (
"StaticFiles",
"FileResponse",
Expand Down Expand Up @@ -53,7 +55,9 @@ def __init__(self, *, directory: str | os.PathLike[str]):
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
if scope["type"] != "http":
raise AssertionError("StaticFiles can't handle non-http request")
path = scope["path"]
# following starlette >=0.33, tested to be compatible with 0.32-0.37.2
root_path = scope.get("route_root_path", scope.get("root_path", ""))
path = scope.get("route_path", re.sub(r"^" + root_path, "", scope["path"]))
path_segments = path.split("/")
final_path, trailing_slash = _traverse_url_path(self.dir, path_segments)
if final_path is None:
Expand Down