(self, path: str, scope: Scope)
| 1893 | return os.path.normpath(os.path.join(*path.split("/"))) |
| 1894 | |
| 1895 | async def get_response(self, path: str, scope: Scope) -> Response: |
| 1896 | if scope["method"] not in ("GET", "HEAD"): |
| 1897 | if await self._lookup_static_resource(path) is not None: |
| 1898 | raise HTTPException(status_code=405) |
| 1899 | raise HTTPException(status_code=404) |
| 1900 | |
| 1901 | static_resource = await self._lookup_static_resource(path) |
| 1902 | if static_resource is not None: |
| 1903 | full_path, stat_result, is_directory_index = static_resource |
| 1904 | if is_directory_index and not scope["path"].endswith("/"): |
| 1905 | url = URL(scope=scope) |
| 1906 | url = url.replace(path=url.path + "/") |
| 1907 | return RedirectResponse(url=url) |
| 1908 | return self.file_response(full_path, stat_result, scope) |
| 1909 | |
| 1910 | if self.fallback == "404.html" or ( |
| 1911 | self.fallback == "auto" and self._fallback_file_exists("404.html") |
| 1912 | ): |
| 1913 | return await self._fallback_response("404.html", scope, status_code=404) |
| 1914 | |
| 1915 | if ( |
| 1916 | self.fallback == "index.html" |
| 1917 | or (self.fallback == "auto" and self._fallback_file_exists("index.html")) |
| 1918 | ) and _is_frontend_navigation_request(scope): |
| 1919 | return await self._fallback_response("index.html", scope, status_code=200) |
| 1920 | |
| 1921 | raise HTTPException(status_code=404) |
| 1922 | |
| 1923 | async def _lookup_path(self, path: str) -> tuple[str, os.stat_result | None]: |
| 1924 | try: |
nothing calls this directly
no test coverage detected