Skip to content

Commit

Permalink
redirect .bit domains to hash actual addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
caryoscelus committed Sep 19, 2022
1 parent 128ff2d commit 53d51e8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Ui/UiRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "/")
Expand Down Expand Up @@ -634,7 +634,9 @@ def parsePath(self, path):
match = re.match(r"/(media/)?(?P<address>[A-Za-z0-9]+[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", 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("/")
Expand All @@ -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)

Expand Down

0 comments on commit 53d51e8

Please sign in to comment.