Skip to content

AddProcessTimeHeaderMiddleware

Middleware to add Server-Timing header with proxy processing time.

AddProcessTimeHeaderMiddleware

Bases: BaseHTTPMiddleware

Middleware to add Server-Timing header with proxy processing time.

Source code in src/stac_auth_proxy/middleware/AddProcessTimeHeaderMiddleware.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class AddProcessTimeHeaderMiddleware(BaseHTTPMiddleware):
    """Middleware to add Server-Timing header with proxy processing time."""

    async def dispatch(self, request: Request, call_next) -> Response:
        """Add Server-Timing header with proxy processing time to the response."""
        start_time = time.perf_counter()
        response = await call_next(request)
        process_time = time.perf_counter() - start_time

        # Add Server-Timing header with proxy processing time
        response.headers["Server-Timing"] = build_server_timing_header(
            response.headers.get("Server-Timing"),
            name="proxy",
            dur=process_time,
            desc="Proxy processing time",
        )

        return response

dispatch(request: Request, call_next) -> Response async

Add Server-Timing header with proxy processing time to the response.

Source code in src/stac_auth_proxy/middleware/AddProcessTimeHeaderMiddleware.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
async def dispatch(self, request: Request, call_next) -> Response:
    """Add Server-Timing header with proxy processing time to the response."""
    start_time = time.perf_counter()
    response = await call_next(request)
    process_time = time.perf_counter() - start_time

    # Add Server-Timing header with proxy processing time
    response.headers["Server-Timing"] = build_server_timing_header(
        response.headers.get("Server-Timing"),
        name="proxy",
        dur=process_time,
        desc="Proxy processing time",
    )

    return response