Bird
0
0

Given this middleware snippet, what will be added to the response headers?

medium📝 component behavior Q4 of 15
FastAPI - Middleware and Hooks
Given this middleware snippet, what will be added to the response headers? ```python class TimingMiddleware(BaseHTTPMiddleware): async def dispatch(self, request, call_next): start = time.time() response = await call_next(request) duration = time.time() - start response.headers["X-Process-Time"] = str(duration) return response ```
AA header 'X-Process-Time' with the request processing duration in seconds
BA header 'X-Process-Time' with the request method name
CA header 'X-Process-Time' with the client IP address
DNo header will be added
Step-by-Step Solution
Solution:
  1. Step 1: Analyze header assignment

    The code sets response.headers["X-Process-Time"] to the duration calculated as time difference.
  2. Step 2: Understand what duration represents

    Duration is the time taken to process the request in seconds.
  3. Final Answer:

    A header 'X-Process-Time' with the request processing duration in seconds -> Option A
  4. Quick Check:

    Header X-Process-Time = duration seconds [OK]
Quick Trick: Middleware adds timing header with duration in seconds [OK]
Common Mistakes:
MISTAKES
  • Assuming header contains method or IP
  • Thinking no header is added
  • Confusing header name or value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes