kenton-li commited on
Commit
3e43332
1 Parent(s): 9103b97

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -12
main.py CHANGED
@@ -1,6 +1,5 @@
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,22 +22,18 @@ async def proxy(request: Request, path: str):
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,
39
- headers=dict(response.headers)
40
  )
41
 
42
  if __name__ == "__main__":
43
  import os
44
- os.system("uvicorn main:app --host 0.0.0.0 --port 7860")
 
1
  from fastapi import FastAPI, Request
2
  from fastapi.responses import Response
 
3
  import httpx
4
 
5
  app = FastAPI()
 
22
  content=content
23
  )
24
 
25
+ # Process the Location header if present in the response
26
+ response_headers = dict(response.headers)
27
+ if "Location" in response_headers:
28
+ # Replace the target URL with the proxy URL
29
+ response_headers["Location"] = response_headers["Location"].replace("http://www.medicalgpt.club", request.base_url)
 
 
 
 
30
 
31
  return Response(
32
  content=response.content,
33
  status_code=response.status_code,
34
+ headers=response_headers
35
  )
36
 
37
  if __name__ == "__main__":
38
  import os
39
+ os.system("uvicorn main:app --host 0.0.0.0 --port 7860")