Update app.py
Browse files
app.py
CHANGED
@@ -11,25 +11,14 @@ app = FastAPI()
|
|
11 |
|
12 |
@app.api_route("/{full_path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"])
|
13 |
async def proxy(request: Request, full_path: str):
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
"
|
18 |
-
|
19 |
-
"
|
20 |
-
|
21 |
-
|
22 |
-
body = await request.body()
|
23 |
-
if body:
|
24 |
-
try:
|
25 |
-
log_data["body"] = json.loads(body)
|
26 |
-
except json.JSONDecodeError:
|
27 |
-
log_data["body"] = body.decode()
|
28 |
-
|
29 |
-
log_message = f"Intercepted request: {json.dumps(log_data, indent=2)}"
|
30 |
-
logger.info(log_message)
|
31 |
-
|
32 |
-
return JSONResponse(content={"message": "Request logged", "data": log_data})
|
33 |
|
34 |
if __name__ == "__main__":
|
35 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
11 |
|
12 |
@app.api_route("/{full_path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"])
|
13 |
async def proxy(request: Request, full_path: str):
|
14 |
+
auth_header = request.headers.get("authorization")
|
15 |
+
|
16 |
+
if auth_header:
|
17 |
+
log_message = f"Intercepted authorization header: {auth_header}"
|
18 |
+
logger.info(log_message)
|
19 |
+
return JSONResponse(content={"message": "Authorization logged", "authorization": auth_header})
|
20 |
+
else:
|
21 |
+
return JSONResponse(content={"message": "No authorization header found"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
if __name__ == "__main__":
|
24 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|