diff --git a/server.py b/server.py index 9d4dc57..4e6aaf7 100644 --- a/server.py +++ b/server.py @@ -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}")