mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Fixed #31982 -- Made HttpResponse.set_cookie() cast max_age argument to an integer.
This commit is contained in:
parent
e6b5108acc
commit
d2d08c8cf6
@ -184,7 +184,7 @@ class HttpResponseBase:
|
|||||||
else:
|
else:
|
||||||
self.cookies[key]['expires'] = ''
|
self.cookies[key]['expires'] = ''
|
||||||
if max_age is not None:
|
if max_age is not None:
|
||||||
self.cookies[key]['max-age'] = max_age
|
self.cookies[key]['max-age'] = int(max_age)
|
||||||
# IE requires expires, so set it if hasn't been already.
|
# IE requires expires, so set it if hasn't been already.
|
||||||
if not expires:
|
if not expires:
|
||||||
self.cookies[key]['expires'] = http_date(time.time() + max_age)
|
self.cookies[key]['expires'] = http_date(time.time() + max_age)
|
||||||
|
@ -834,8 +834,8 @@ Methods
|
|||||||
Sets a cookie. The parameters are the same as in the
|
Sets a cookie. The parameters are the same as in the
|
||||||
:class:`~http.cookies.Morsel` cookie object in the Python standard library.
|
:class:`~http.cookies.Morsel` cookie object in the Python standard library.
|
||||||
|
|
||||||
* ``max_age`` should be a number of seconds, or ``None`` (default) if
|
* ``max_age`` should be an integer number of seconds, or ``None`` (default)
|
||||||
the cookie should last only as long as the client's browser session.
|
if the cookie should last only as long as the client's browser session.
|
||||||
If ``expires`` is not specified, it will be calculated.
|
If ``expires`` is not specified, it will be calculated.
|
||||||
* ``expires`` should either be a string in the format
|
* ``expires`` should either be a string in the format
|
||||||
``"Wdy, DD-Mon-YY HH:MM:SS GMT"`` or a ``datetime.datetime`` object
|
``"Wdy, DD-Mon-YY HH:MM:SS GMT"`` or a ``datetime.datetime`` object
|
||||||
|
@ -65,6 +65,11 @@ class SetCookieTests(SimpleTestCase):
|
|||||||
self.assertEqual(max_age_cookie['max-age'], 10)
|
self.assertEqual(max_age_cookie['max-age'], 10)
|
||||||
self.assertEqual(max_age_cookie['expires'], http_date(set_cookie_time + 10))
|
self.assertEqual(max_age_cookie['expires'], http_date(set_cookie_time + 10))
|
||||||
|
|
||||||
|
def test_max_age_int(self):
|
||||||
|
response = HttpResponse()
|
||||||
|
response.set_cookie('max_age', max_age=10.6)
|
||||||
|
self.assertEqual(response.cookies['max_age']['max-age'], 10)
|
||||||
|
|
||||||
def test_httponly_cookie(self):
|
def test_httponly_cookie(self):
|
||||||
response = HttpResponse()
|
response = HttpResponse()
|
||||||
response.set_cookie('example', httponly=True)
|
response.set_cookie('example', httponly=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user