Update fun.py
Browse files
fun.py
CHANGED
@@ -7,7 +7,7 @@ import websockets
|
|
7 |
app = FastAPI()
|
8 |
|
9 |
TARGET_BASE = "http://127.0.0.1:9222" # 目标服务器(Chrome DevTools)
|
10 |
-
TARGET_WS_BASE = "ws://127.0.0.1
|
11 |
|
12 |
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
|
13 |
async def proxy(request: Request, path: str):
|
@@ -39,7 +39,7 @@ async def websocket_proxy(websocket: WebSocket, path: str):
|
|
39 |
await websocket.accept()
|
40 |
target_url = f"{TARGET_WS_BASE}/{path}"
|
41 |
try:
|
42 |
-
async with websockets.connect(target_url) as target_ws:
|
43 |
async def client_to_server():
|
44 |
while True:
|
45 |
data = await websocket.receive_text()
|
|
|
7 |
app = FastAPI()
|
8 |
|
9 |
TARGET_BASE = "http://127.0.0.1:9222" # 目标服务器(Chrome DevTools)
|
10 |
+
TARGET_WS_BASE = "ws://127.0.0.1" # WebSocket 目标
|
11 |
|
12 |
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"])
|
13 |
async def proxy(request: Request, path: str):
|
|
|
39 |
await websocket.accept()
|
40 |
target_url = f"{TARGET_WS_BASE}/{path}"
|
41 |
try:
|
42 |
+
async with websockets.connect(target_url, extra_headers={"Host": "127.0.0.1"}) as target_ws:
|
43 |
async def client_to_server():
|
44 |
while True:
|
45 |
data = await websocket.receive_text()
|