Update fun.py
Browse files
fun.py
CHANGED
@@ -14,9 +14,9 @@ async def proxy(request: Request, path: str):
|
|
14 |
|
15 |
url = f"{TARGET_BASE}/{path}"
|
16 |
headers = dict(request.headers)
|
17 |
-
|
18 |
# 强制 Host 头为 127.0.0.1,避免 Chrome 拒绝
|
19 |
-
|
20 |
body = await request.body()
|
21 |
async with httpx.AsyncClient(follow_redirects=True) as client:
|
22 |
resp = await client.request(
|
@@ -26,10 +26,12 @@ async def proxy(request: Request, path: str):
|
|
26 |
content=body,
|
27 |
params=request.query_params
|
28 |
)
|
|
|
|
|
29 |
return Response(
|
30 |
content=resp.content,
|
31 |
status_code=resp.status_code,
|
32 |
-
headers=
|
33 |
)
|
34 |
|
35 |
@app.websocket("/{path:path}")
|
|
|
14 |
|
15 |
url = f"{TARGET_BASE}/{path}"
|
16 |
headers = dict(request.headers)
|
17 |
+
host = headers["host"]
|
18 |
# 强制 Host 头为 127.0.0.1,避免 Chrome 拒绝
|
19 |
+
headers["host"] = "127.0.0.1"
|
20 |
body = await request.body()
|
21 |
async with httpx.AsyncClient(follow_redirects=True) as client:
|
22 |
resp = await client.request(
|
|
|
26 |
content=body,
|
27 |
params=request.query_params
|
28 |
)
|
29 |
+
headers = dict(resp.headers)
|
30 |
+
headers["host"] = host
|
31 |
return Response(
|
32 |
content=resp.content,
|
33 |
status_code=resp.status_code,
|
34 |
+
headers=dheaders
|
35 |
)
|
36 |
|
37 |
@app.websocket("/{path:path}")
|