feat: X-Host-Only

This commit is contained in:
2026-04-21 22:51:35 +02:00
parent 18c718d24a
commit c0c281e25c
11 changed files with 229 additions and 60 deletions
+24 -7
View File
@@ -16,6 +16,7 @@ class Registry:
]
HOST_FILE = ".host"
HOST_ONLY_FILE = ".host_only"
TOKEN_FILE = ".token" # noqa: S105
REDIRECT_FILE = ".redirect"
PROXY_FILE = ".proxy"
@@ -34,22 +35,38 @@ class Registry:
return [p.host for p in self.pages.values() if p.host is not None]
def add(self, path: str) -> None:
host = self.data_dir.get_file(path, self.HOST_FILE)
host_only = self.data_dir.get_file(path, self.HOST_ONLY_FILE)
self.pages[path] = Page(
path,
self.data_dir.has_index(path),
self.data_dir.get_file(path, self.HOST_FILE),
self.data_dir.get_file(path, self.TOKEN_FILE),
self.data_dir.get_file(path, self.REDIRECT_FILE),
self.data_dir.get_file(path, self.PROXY_FILE),
path=path,
with_index=self.data_dir.has_index(path),
host=host if host is not None else host_only,
host_only=host_only is not None,
token_hash=self.data_dir.get_file(path, self.TOKEN_FILE),
redirect=self.data_dir.get_file(path, self.REDIRECT_FILE),
proxy=self.data_dir.get_file(path, self.PROXY_FILE),
)
self.logger.info("Updated %s", self.pages[path])
def set_host(self, path: str, host: str) -> None:
if path in self.pages and self.pages[path].host != host:
if path in self.pages and (
self.pages[path].host != host or self.pages[path].host_only
):
self.data_dir.set_file(path, self.HOST_FILE, host)
self.data_dir.remove_file(path, self.HOST_ONLY_FILE)
self.pages[path].host = host
self.logger.debug("Updated %s", self.pages[path])
def set_host_only(self, path: str, host: str) -> None:
if path in self.pages and (
self.pages[path].host != host or not self.pages[path].host_only
):
self.data_dir.set_file(path, self.HOST_ONLY_FILE, host)
self.data_dir.remove_file(path, self.HOST_FILE)
self.pages[path].host = host
self.pages[path].host_only = True
self.logger.debug("Updated %s", self.pages[path])
def set_token_hash(self, path: str, token_hash: str) -> None:
if path in self.pages and self.pages[path].token_hash != token_hash:
self.data_dir.set_file(path, self.TOKEN_FILE, token_hash, 0o600)