Skip to content

SlowAPIASGIMiddleware crashes on streaming responses #260

@davidpoblador

Description

@davidpoblador

When using SlowAPIASGIMiddleware with anything that streams (like FileResponse or StaticFiles), it crashes with:

RuntimeError: ASGI flow error: Response already started

The problem is in _ASGIMiddlewareResponder.send_wrapper — it sends http.response.start on every http.response.body chunk instead of just the first one. Streaming responses send multiple body chunks with more_body=True, so the second chunk triggers the error because the response was already started.

Easy to reproduce: just mount a StaticFiles directory and request any file through the middleware.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions