diff options
| author | Illia Volochii <illia.volochii@gmail.com> | 2021-01-28 07:28:14 +0200 |
|---|---|---|
| committer | Carlton Gibson <carlton@noumenal.es> | 2021-01-28 10:10:08 +0100 |
| commit | 3c004075b1d4fe4aa1ffc3f7d699dd9525bc6c02 (patch) | |
| tree | 00cfbc4e07ccd052a758be3714e4546b80ae1855 | |
| parent | 241da3f06ee0c6f436341cda5890b221ac453e3b (diff) | |
Fixed #32389 -- Fixed ResponseHeaders crash when data is not mapping.
| -rw-r--r-- | django/http/response.py | 9 | ||||
| -rw-r--r-- | tests/httpwrappers/tests.py | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/django/http/response.py b/django/http/response.py index 0d23c1312f..1c22edaff3 100644 --- a/django/http/response.py +++ b/django/http/response.py @@ -16,7 +16,9 @@ from django.core.exceptions import DisallowedRedirect from django.core.serializers.json import DjangoJSONEncoder from django.http.cookie import SimpleCookie from django.utils import timezone -from django.utils.datastructures import CaseInsensitiveMapping +from django.utils.datastructures import ( + CaseInsensitiveMapping, _destruct_iterable_mapping_values, +) from django.utils.encoding import iri_to_uri from django.utils.http import http_date from django.utils.regex_helper import _lazy_re_compile @@ -31,10 +33,7 @@ class ResponseHeaders(CaseInsensitiveMapping): correctly encoded. """ if not isinstance(data, Mapping): - data = { - k: v - for k, v in CaseInsensitiveMapping._destruct_iterable_mapping_values(data) - } + data = {k: v for k, v in _destruct_iterable_mapping_values(data)} self._store = {} for header, value in data.items(): self[header] = value diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index cbf8b7d586..728e879b5c 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -835,6 +835,10 @@ class HttpResponseHeadersTestCase(SimpleTestCase): # del doesn't raise a KeyError on nonexistent headers. del response['X-Foo'] + def test_headers_as_iterable_of_tuple_pairs(self): + response = HttpResponse(headers=(('X-Foo', 'bar'),)) + self.assertEqual(response['X-Foo'], 'bar') + def test_headers_bytestring(self): response = HttpResponse() response['X-Foo'] = b'bar' |
