kenton-li commited on
Commit
9103b97
·
1 Parent(s): d1ce9aa

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -0
main.py CHANGED
@@ -1,5 +1,6 @@
1
  from fastapi import FastAPI, Request
2
  from fastapi.responses import Response
 
3
  import httpx
4
 
5
  app = FastAPI()
@@ -22,6 +23,16 @@ async def proxy(request: Request, path: str):
22
  content=content
23
  )
24
 
 
 
 
 
 
 
 
 
 
 
25
  return Response(
26
  content=response.content,
27
  status_code=response.status_code,
 
1
  from fastapi import FastAPI, Request
2
  from fastapi.responses import Response
3
+ from urllib.parse import urljoin
4
  import httpx
5
 
6
  app = FastAPI()
 
23
  content=content
24
  )
25
 
26
+ # Check if there's a Location header (indicating a redirect)
27
+ if "Location" in response.headers:
28
+ # Modify the location to pass through the proxy
29
+ location = response.headers["Location"]
30
+
31
+ # Construct a new URL that goes through the proxy
32
+ new_location = urljoin(f"http://{request.url.netloc}", location)
33
+
34
+ response.headers["Location"] = new_location
35
+
36
  return Response(
37
  content=response.content,
38
  status_code=response.status_code,