File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
src/stac_auth_proxy/middleware Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 1- """Middleware to add a header with the process time to the response ."""
1+ """Middleware to add Server-Timing header with proxy processing time."""
22
33import time
44
77
88
99class AddProcessTimeHeaderMiddleware (BaseHTTPMiddleware ):
10- """Middleware to add a header with the process time to the response ."""
10+ """Middleware to add Server-Timing header with proxy processing time."""
1111
1212 async def dispatch (self , request : Request , call_next ) -> Response :
13- """Add a header with the process time to the response."""
13+ """Add Server-Timing header with proxy processing time to the response."""
1414 start_time = time .perf_counter ()
1515 response = await call_next (request )
1616 process_time = time .perf_counter () - start_time
17- response .headers ["X-Process-Time" ] = f"{ process_time :.3f} "
17+
18+ # Add Server-Timing header with proxy processing time
19+ # Format: Server-Timing: proxy;dur=123.456
20+ server_timing_value = f"proxy;dur={ process_time :.3f} "
21+
22+ # If there's already a Server-Timing header, append to it
23+ existing_timing = response .headers .get ("Server-Timing" )
24+ if existing_timing :
25+ response .headers ["Server-Timing" ] = (
26+ f"{ existing_timing } , { server_timing_value } "
27+ )
28+ else :
29+ response .headers ["Server-Timing" ] = server_timing_value
30+
1831 return response
You can’t perform that action at this time.
0 commit comments