robinhad commited on
Commit
dff12a4
·
verified ·
1 Parent(s): e0fd21e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -15,6 +15,29 @@ CUSTOM_PATH = "/gradio"
15
 
16
  app = FastAPI()
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  # This should be a secure secret key in a real application
20
  SECRET_KEY = "your_secret_key_here"
@@ -90,7 +113,6 @@ async def translate(
90
  raise HTTPException(
91
  status_code=400, detail={"message": "Missing required parameters"}
92
  )
93
- print(await request)
94
  data = await request.json()
95
  strings = data.get("strings", [])
96
 
 
15
 
16
  app = FastAPI()
17
 
18
+ class LoggingMiddleware(BaseHTTPMiddleware):
19
+ async def dispatch(self, request: Request, call_next):
20
+ # Log request info
21
+ logger.info(f"--- RAW REQUEST ---")
22
+ logger.info(f"Method: {request.method}")
23
+ logger.info(f"URL: {request.url}")
24
+ logger.info("Headers:")
25
+ for name, value in request.headers.items():
26
+ logger.info(f" {name}: {value}")
27
+
28
+ # Get raw body
29
+ body = await request.body()
30
+ logger.info("Body:")
31
+ logger.info(body.decode())
32
+ logger.info("--- END RAW REQUEST ---")
33
+
34
+ # We need to set the body again since we've already read it
35
+ request._body = body
36
+
37
+ response = await call_next(request)
38
+ return response
39
+
40
+ app.add_middleware(LoggingMiddleware)
41
 
42
  # This should be a secure secret key in a real application
43
  SECRET_KEY = "your_secret_key_here"
 
113
  raise HTTPException(
114
  status_code=400, detail={"message": "Missing required parameters"}
115
  )
 
116
  data = await request.json()
117
  strings = data.get("strings", [])
118