From: Marcelo Trylesinski Date: Fri, 6 May 2022 06:03:16 +0000 (+0200) Subject: Do not send empty data to `StreamingResponse` on `BaseHTTPMiddleware` (#1609) X-Git-Tag: 0.20.1~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b8ea367b4304a98653ec8ce9c794ad0ba6dcaf4b;p=thirdparty%2Fstarlette.git Do not send empty data to `StreamingResponse` on `BaseHTTPMiddleware` (#1609) Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Co-authored-by: Tom Christie --- diff --git a/starlette/middleware/base.py b/starlette/middleware/base.py index ca9deb7d..49a5e3e2 100644 --- a/starlette/middleware/base.py +++ b/starlette/middleware/base.py @@ -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