Spaces:
Sleeping
Sleeping
Update components/middleware.py
Browse files- components/middleware.py +13 -12
components/middleware.py
CHANGED
|
@@ -282,27 +282,28 @@ class x401Kit(BaseHTTPMiddleware):
|
|
| 282 |
if response.headers.get("content-type") == "application/json":
|
| 283 |
|
| 284 |
body_bytes = b""
|
| 285 |
-
|
| 286 |
-
|
|
|
|
| 287 |
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
|
| 293 |
|
| 294 |
-
|
| 295 |
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
|
| 300 |
-
|
| 301 |
content=data,
|
| 302 |
status_code=response.status_code,
|
| 303 |
headers=response_headers
|
| 304 |
)
|
| 305 |
-
|
| 306 |
|
| 307 |
return response
|
| 308 |
|
|
|
|
| 282 |
if response.headers.get("content-type") == "application/json":
|
| 283 |
|
| 284 |
body_bytes = b""
|
| 285 |
+
|
| 286 |
+
async for chunk in response.body_iterator:
|
| 287 |
+
body_bytes += chunk
|
| 288 |
|
| 289 |
+
try:
|
| 290 |
+
data = json.loads(body_bytes.decode())
|
| 291 |
+
except json.JSONDecodeError:
|
| 292 |
+
return response
|
| 293 |
|
| 294 |
|
| 295 |
+
data["address"] = X_401_Addr
|
| 296 |
|
| 297 |
+
response_headers = dict(response.headers)
|
| 298 |
+
response_headers.pop("content-length", None)
|
| 299 |
+
print(data)
|
| 300 |
|
| 301 |
+
return JSONResponse(
|
| 302 |
content=data,
|
| 303 |
status_code=response.status_code,
|
| 304 |
headers=response_headers
|
| 305 |
)
|
| 306 |
+
|
| 307 |
|
| 308 |
return response
|
| 309 |
|