Corvius commited on
Commit
e382c3e
·
verified ·
1 Parent(s): 3a586bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -19
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
- log_data = {
15
- "method": request.method,
16
- "url": str(request.url),
17
- "headers": dict(request.headers),
18
- "query_params": dict(request.query_params),
19
- "client_host": request.client.host,
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)