]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Fixed TestClient error when response headers missing (#1200)
authorAber <Chen_Ye@ahnu.edu.cn>
Mon, 21 Jun 2021 08:09:19 +0000 (16:09 +0800)
committerGitHub <noreply@github.com>
Mon, 21 Jun 2021 08:09:19 +0000 (10:09 +0200)
* Fixed https://github.com/abersheeran/asgi-ratelimit/issues/14

* lint it

* Black it

Co-authored-by: euri10 <euri10@users.noreply.github.com>
starlette/testclient.py

index c1c0fe1652adaff3d5f9e68486ebb194aeb0bc84..6675f49714b03e247266d432f4c6d6cba0cfd0b8 100644 (file)
@@ -214,7 +214,8 @@ class _ASGIAdapter(requests.adapters.HTTPAdapter):
                 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(