Correctly follow same-domain redirects

This commit is contained in:
Nexus 2024-02-22 18:09:57 +00:00
parent b8079e1db0
commit 572548716a
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -230,14 +230,23 @@ def preview_url(
domain = os.environ.get("PREVIEW_HOMESERVER", "https://" + req.url.hostname)
try:
response = httpx.get(
url,
with httpx.Client(
headers={
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
},
timeout=60,
follow_redirects=True
follow_redirects=False
) as client:
response = client.get(
url,
headers={
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
},
)
response.raise_for_status()
while response.next_request and response.next_request.url.host == response.url.host:
response = client.send(response.next_request)
response.raise_for_status()
except httpx.HTTPError as e:
raise HTTPException(500, f"Failed to fetch URL: {e!r}")