Fix Correctly follow same-domain redirects

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

View file

@ -243,10 +243,12 @@ def preview_url(
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0" "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
}, },
) )
response.raise_for_status() if response.status_code not in range(200, 400):
response.raise_for_status()
while response.next_request and response.next_request.url.host == response.url.host: while response.next_request and response.next_request.url.host == response.url.host:
response = client.send(response.next_request) response = client.send(response.next_request)
response.raise_for_status() if response.status_code not in range(200, 400):
response.raise_for_status()
except httpx.HTTPError as e: except httpx.HTTPError as e:
raise HTTPException(500, f"Failed to fetch URL: {e!r}") raise HTTPException(500, f"Failed to fetch URL: {e!r}")