]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Do not send empty data to `StreamingResponse` on `BaseHTTPMiddleware` (#1609)
authorMarcelo Trylesinski <marcelotryle@gmail.com>
Fri, 6 May 2022 06:03:16 +0000 (08:03 +0200)
committerGitHub <noreply@github.com>
Fri, 6 May 2022 06:03:16 +0000 (08:03 +0200)
Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Co-authored-by: Tom Christie <tom@tomchristie.com>
starlette/middleware/base.py

index ca9deb7de5b3673d407a112c705098a5a2e460e7..49a5e3e2d7a0a96cd0f7e83f6b9f527d074d4280 100644 (file)
@@ -52,7 +52,11 @@ class BaseHTTPMiddleware:
                 async with recv_stream:
                     async for message in recv_stream:
                         assert message["type"] == "http.response.body"
-                        yield message.get("body", b"")
+                        body = message.get("body", b"")
+                        if body:
+                            yield body
+                        if not message.get("more_body", False):
+                            break
 
                 if app_exc is not None:
                     raise app_exc