Correctly follow same-domain redirects
This commit is contained in:
parent
b8079e1db0
commit
572548716a
1 changed files with 13 additions and 4 deletions
17
server.py
17
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}")
|
||||
|
||||
|
|
Loading…
Reference in a new issue