Loading django/http/response.py +2 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ from django.core.exceptions import DisallowedRedirect from django.core.serializers.json import DjangoJSONEncoder from django.http.cookie import SimpleCookie from django.utils import six, timezone from django.utils.encoding import force_bytes, force_text, iri_to_uri from django.utils.encoding import force_bytes, force_text, force_str, iri_to_uri from django.utils.http import cookie_date from django.utils.six.moves import map from django.utils.six.moves.urllib.parse import urlparse Loading Loading @@ -221,6 +221,7 @@ class HttpResponseBase(six.Iterator): If it is a ``datetime.datetime`` object then ``max_age`` will be calculated. """ value = force_str(value) self.cookies[key] = value if expires is not None: if isinstance(expires, datetime.datetime): Loading tests/requests/tests.py +8 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ from django.test import SimpleTestCase, RequestFactory, override_settings from django.test.client import FakePayload from django.test.utils import str_prefix from django.utils import six from django.utils.encoding import force_str from django.utils.http import cookie_date, urlencode from django.utils.six.moves.urllib.parse import urlencode as original_urlencode from django.utils.timezone import utc Loading Loading @@ -193,6 +194,13 @@ class RequestsTests(SimpleTestCase): self.assertTrue('; httponly' in str(example_cookie)) self.assertTrue(example_cookie['httponly']) def test_unicode_cookie(self): "Verify HttpResponse.set_cookie() works with unicode data." response = HttpResponse() cookie_value = '清風' response.set_cookie('test', cookie_value) self.assertEqual(force_str(cookie_value), response.cookies['test'].value) def test_limited_stream(self): # Read all of a limited stream stream = LimitedStream(BytesIO(b'test'), 2) Loading Loading
django/http/response.py +2 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,7 @@ from django.core.exceptions import DisallowedRedirect from django.core.serializers.json import DjangoJSONEncoder from django.http.cookie import SimpleCookie from django.utils import six, timezone from django.utils.encoding import force_bytes, force_text, iri_to_uri from django.utils.encoding import force_bytes, force_text, force_str, iri_to_uri from django.utils.http import cookie_date from django.utils.six.moves import map from django.utils.six.moves.urllib.parse import urlparse Loading Loading @@ -221,6 +221,7 @@ class HttpResponseBase(six.Iterator): If it is a ``datetime.datetime`` object then ``max_age`` will be calculated. """ value = force_str(value) self.cookies[key] = value if expires is not None: if isinstance(expires, datetime.datetime): Loading
tests/requests/tests.py +8 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ from django.test import SimpleTestCase, RequestFactory, override_settings from django.test.client import FakePayload from django.test.utils import str_prefix from django.utils import six from django.utils.encoding import force_str from django.utils.http import cookie_date, urlencode from django.utils.six.moves.urllib.parse import urlencode as original_urlencode from django.utils.timezone import utc Loading Loading @@ -193,6 +194,13 @@ class RequestsTests(SimpleTestCase): self.assertTrue('; httponly' in str(example_cookie)) self.assertTrue(example_cookie['httponly']) def test_unicode_cookie(self): "Verify HttpResponse.set_cookie() works with unicode data." response = HttpResponse() cookie_value = '清風' response.set_cookie('test', cookie_value) self.assertEqual(force_str(cookie_value), response.cookies['test'].value) def test_limited_stream(self): # Read all of a limited stream stream = LimitedStream(BytesIO(b'test'), 2) Loading