From 53d51e8bc88ae408709f48ffcedc63251da1a8e8 Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Mon, 19 Sep 2022 16:05:25 +0000 Subject: [PATCH] redirect .bit domains to hash actual addresses refs #23 --- src/Ui/UiRequest.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Ui/UiRequest.py b/src/Ui/UiRequest.py index e34d22cb6..1b2d5cf31 100644 --- a/src/Ui/UiRequest.py +++ b/src/Ui/UiRequest.py @@ -372,7 +372,7 @@ def formatRedirect(self, url): # Redirect to an url def actionRedirect(self, url): self.start_response('301 Redirect', [('Location', str(url))]) - yield self.formatRedirect(url) + return self.formatRedirect(url) def actionIndex(self): return self.actionRedirect("/" + config.homepage + "/") @@ -634,7 +634,9 @@ def parsePath(self, path): match = re.match(r"/(media/)?(?P
[A-Za-z0-9]+[A-Za-z0-9\._-]+)(?P/.*|$)", path) if match: path_parts = match.groupdict() - if self.isDomain(path_parts["address"]): + addr = path_parts["address"] + if self.isDomain(addr): + path_parts["domain"] = addr path_parts["address"] = self.resolveDomain(path_parts["address"]) path_parts["request_address"] = path_parts["address"] # Original request address (for Merger sites) path_parts["inner_path"] = path_parts["inner_path"].lstrip("/") @@ -651,6 +653,12 @@ def actionSiteMedia(self, path, header_length=True, header_noscript=False): except SecurityError as err: return self.error403(err) + if "domain" in path_parts: + addr = path_parts['address'] + path = path_parts['inner_path'] + query = self.env['QUERY_STRING'] + return self.actionRedirect(f"/{addr}/{path}?{query}") + if not path_parts: return self.error404(path)