-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Closed
Description
Privileged issue
- I'm @tiangolo or he asked me directly to create an issue here.
Issue Content
I use fastapi 0.99.1
Here is my custom middleware
import time
from fastapi import Request
from starlette.middleware.base import BaseHTTPMiddleware
from uvicorn.protocols.utils import get_path_with_query_string
from starlette.responses import StreamingResponse
from app.core.logger import access_logger as logger
class AccessLogMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request: Request, call_next):
start_time = time.perf_counter_ns()
response: StreamingResponse = await call_next(request)
end_time = time.perf_counter_ns()
process_time = round((end_time - start_time) / 10**9, 3)
status_code = response.status_code
path = get_path_with_query_string(request.scope)
client_host = request.client.host
client_port = request.client.port
http_method = request.method
content = response.content
logger.info(
f"{http_method} | status_code: {status_code} | {path} | time: {process_time} s | {client_host}:{client_port} | content: {content}")
return responseAn exception will be thrown here:'_StreamingResponse' object has no attribute 'content'
I would like to ask how to solve it, thank you
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels