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(