Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -33,6 +33,7 @@ def handle_sigterm(signum, frame):
|
|
33 |
|
34 |
signal.signal(signal.SIGTERM, handle_sigterm)
|
35 |
|
|
|
36 |
|
37 |
@app.on_event("shutdown")
|
38 |
def shutdown_event():
|
@@ -47,7 +48,7 @@ async def route_with_config():
|
|
47 |
|
48 |
|
49 |
async def proxy_to_node(request: Request):
|
50 |
-
|
51 |
|
52 |
# Preserve the full path including query parameters
|
53 |
full_path = request.url.path
|
@@ -61,20 +62,29 @@ async def proxy_to_node(request: Request):
|
|
61 |
for k, v in request.headers.items()
|
62 |
if k.lower() not in ["host", "content-length"]
|
63 |
}
|
64 |
-
body = await request.body()
|
65 |
|
66 |
-
async with client:
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
return StreamingResponse(
|
72 |
-
|
73 |
-
status_code=response.status_code,
|
74 |
-
headers=response.headers,
|
75 |
)
|
76 |
|
77 |
|
|
|
78 |
@app.api_route(
|
79 |
"/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]
|
80 |
)
|
|
|
33 |
|
34 |
signal.signal(signal.SIGTERM, handle_sigterm)
|
35 |
|
36 |
+
client = httpx.AsyncClient()
|
37 |
|
38 |
@app.on_event("shutdown")
|
39 |
def shutdown_event():
|
|
|
48 |
|
49 |
|
50 |
async def proxy_to_node(request: Request):
|
51 |
+
|
52 |
|
53 |
# Preserve the full path including query parameters
|
54 |
full_path = request.url.path
|
|
|
62 |
for k, v in request.headers.items()
|
63 |
if k.lower() not in ["host", "content-length"]
|
64 |
}
|
65 |
+
# body = await request.body()
|
66 |
|
67 |
+
# async with client:
|
68 |
+
# response = await client.request(
|
69 |
+
# method=request.method, url=url, headers=headers, content=body
|
70 |
+
# )
|
71 |
+
|
72 |
+
# return StreamingResponse(
|
73 |
+
# response.iter_bytes(),
|
74 |
+
# status_code=response.status_code,
|
75 |
+
# headers=response.headers,
|
76 |
+
# )
|
77 |
+
|
78 |
+
req = client.build_request("GET", httpx.URL(url), headers=headers)
|
79 |
+
r = await client.send(req, stream=True)
|
80 |
+
print(f"Time to prepare request: {time.time() - start_time:.4f} seconds")
|
81 |
|
82 |
return StreamingResponse(
|
83 |
+
r.aiter_raw(), background=BackgroundTask(r.aclose), headers=r.headers
|
|
|
|
|
84 |
)
|
85 |
|
86 |
|
87 |
+
|
88 |
@app.api_route(
|
89 |
"/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]
|
90 |
)
|