summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/http/response.py2
-rw-r--r--docs/ref/request-response.txt4
-rw-r--r--tests/responses/test_cookie.py5
3 files changed, 8 insertions, 3 deletions
diff --git a/django/http/response.py b/django/http/response.py
index c0ed93c44e..64ac205087 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -184,7 +184,7 @@ class HttpResponseBase:
else:
self.cookies[key]['expires'] = ''
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.
if not expires:
self.cookies[key]['expires'] = http_date(time.time() + max_age)
diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
index 0256713822..6b3ec54dd5 100644
--- a/docs/ref/request-response.txt
+++ b/docs/ref/request-response.txt
@@ -834,8 +834,8 @@ Methods
Sets a cookie. The parameters are the same as in the
:class:`~http.cookies.Morsel` cookie object in the Python standard library.
- * ``max_age`` should be a number of seconds, or ``None`` (default) if
- the cookie should last only as long as the client's browser session.
+ * ``max_age`` should be an integer number of seconds, or ``None`` (default)
+ if the cookie should last only as long as the client's browser session.
If ``expires`` is not specified, it will be calculated.
* ``expires`` should either be a string in the format
``"Wdy, DD-Mon-YY HH:MM:SS GMT"`` or a ``datetime.datetime`` object
diff --git a/tests/responses/test_cookie.py b/tests/responses/test_cookie.py
index c7c35219b2..fd3a55442c 100644
--- a/tests/responses/test_cookie.py
+++ b/tests/responses/test_cookie.py
@@ -65,6 +65,11 @@ class SetCookieTests(SimpleTestCase):
self.assertEqual(max_age_cookie['max-age'], 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):
response = HttpResponse()
response.set_cookie('example', httponly=True)