From 7ed2890146705accb6c3924afb7f5e55010c0a1f Mon Sep 17 00:00:00 2001 From: Aber Date: Mon, 21 Jun 2021 16:09:19 +0800 Subject: [PATCH] Fixed TestClient error when response headers missing (#1200) * Fixed https://github.com/abersheeran/asgi-ratelimit/issues/14 * lint it * Black it Co-authored-by: euri10 --- starlette/testclient.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/starlette/testclient.py b/starlette/testclient.py index c1c0fe165..6675f4971 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -214,7 +214,8 @@ async def send(message: Message) -> None: raw_kwargs["status"] = message["status"] raw_kwargs["reason"] = _get_reason_phrase(message["status"]) raw_kwargs["headers"] = [ - (key.decode(), value.decode()) for key, value in message["headers"] + (key.decode(), value.decode()) + for key, value in message.get("headers", []) ] raw_kwargs["preload_content"] = False raw_kwargs["original_response"] = _MockOriginalResponse(