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.
When using SlowAPIASGIMiddleware with anything that streams (like FileResponse or StaticFiles), it crashes with:
The problem is in
_ASGIMiddlewareResponder.send_wrapper— it sendshttp.response.starton everyhttp.response.bodychunk instead of just the first one. Streaming responses send multiple body chunks withmore_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.