web.internal: Use absolute path for redirect

This commit is contained in:
Unrud 2022-01-18 18:20:15 +01:00
parent 4ed77cabc6
commit 22fc38850c
2 changed files with 3 additions and 5 deletions

View File

@ -26,9 +26,8 @@ class TestBaseWebRequests(BaseTest):
"""Test web plugin.""" """Test web plugin."""
def test_internal(self) -> None: def test_internal(self) -> None:
_, headers, answer = self.request("GET", "/.web", check=302) _, headers, _ = self.request("GET", "/.web", check=302)
assert headers.get("Location") == ".web/" assert headers.get("Location") == "/.web/"
assert answer == "Redirected to .web/"
_, answer = self.get("/.web/") _, answer = self.get("/.web/")
assert answer assert answer
self.post("/.web", check=405) self.post("/.web", check=405)

View File

@ -27,7 +27,6 @@ Features:
import os import os
import posixpath
import time import time
from http import client from http import client
from typing import Mapping from typing import Mapping
@ -75,7 +74,7 @@ class Web(web.BaseWeb):
path, e, exc_info=True) path, e, exc_info=True)
return httputils.NOT_FOUND return httputils.NOT_FOUND
if os.path.isdir(filesystem_path) and not path.endswith("/"): if os.path.isdir(filesystem_path) and not path.endswith("/"):
return httputils.redirect(posixpath.basename(path) + "/") return httputils.redirect(base_prefix + path + "/")
if os.path.isdir(filesystem_path): if os.path.isdir(filesystem_path):
filesystem_path = os.path.join(filesystem_path, "index.html") filesystem_path = os.path.join(filesystem_path, "index.html")
if not os.path.isfile(filesystem_path): if not os.path.isfile(filesystem_path):