Skip to content

Commit

Permalink
Try to fix redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Feb 28, 2024
1 parent 8dc76af commit b106821
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions homu/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,12 @@ def redirect_to_canonical_host():
request_url = urllib.parse.urlparse(request.url)
redirect_url = request_url

# Assume that we're always deployed behind something that hides https:// from us.
# In production TLS is terminated at ELB, so the actual bors app sees only http:// requests.
request_url = redirect_url._replace(
scheme="https"
)

# Disable redirects on the health check endpoint.
if request_url.path == "/health":
return
Expand All @@ -1042,9 +1048,8 @@ def redirect_to_canonical_host():
elif redirect_url.path == "/" + prefix:
redirect_url = redirect_url._replace(path="/")

print("request_url=", request_url)
print("redirect_url=", redirect_url)
if request_url != redirect_url:
print("redirecting original=" + request_url + " to new=" + redirect_url)
redirect(urllib.parse.urlunparse(redirect_url), 301)


Expand Down

0 comments on commit b106821

Please sign in to comment.