Skip to content
  • Andrey Azeev's avatar
    ee54b3f2
    fix!: RequestIdMiddleware as pure-ASGI to prevent Content-Length errors (v0.7.0) · ee54b3f2
    Andrey Azeev authored
    Replace BaseHTTPMiddleware subclass with a pure-ASGI implementation.
    BaseHTTPMiddleware wraps responses in _StreamingResponse and preserves
    the original Content-Length, so streamed bodies (JSONResponse with
    ensure_ascii=False, client disconnects mid-response, CORS+Prometheus+
    RequestId chains) trigger:
    
        RuntimeError: Response content longer than Content-Length
    
    Public API is preserved: import path, app.add_middleware signature,
    HEADER_NAME constant, request.state.request_id, request_id_ctx and the
    echoed x-request-id response header all behave as before.
    
    BREAKING: subclasses overriding `dispatch` will break — the method no
    longer exists. No such consumers found in Lucente.
    
    Refs: encode/starlette#1678
    ee54b3f2
    fix!: RequestIdMiddleware as pure-ASGI to prevent Content-Length errors (v0.7.0)
    Andrey Azeev authored
    Replace BaseHTTPMiddleware subclass with a pure-ASGI implementation.
    BaseHTTPMiddleware wraps responses in _StreamingResponse and preserves
    the original Content-Length, so streamed bodies (JSONResponse with
    ensure_ascii=False, client disconnects mid-response, CORS+Prometheus+
    RequestId chains) trigger:
    
        RuntimeError: Response content longer than Content-Length
    
    Public API is preserved: import path, app.add_middleware signature,
    HEADER_NAME constant, request.state.request_id, request_id_ctx and the
    echoed x-request-id response header all behave as before.
    
    BREAKING: subclasses overriding `dispatch` will break — the method no
    longer exists. No such consumers found in Lucente.
    
    Refs: encode/starlette#1678
Loading