Code

Ticket #13548: set_cookie.diff

File set_cookie.diff, 1.1 KB (added by master, 4 years ago)
Line 
1Index: django/http/__init__.py
2===================================================================
3--- django/http/__init__.py     (revision 13265)
4+++ django/http/__init__.py     (working copy)
5@@ -1,5 +1,6 @@
6 import os
7 import re
8+import time
9 from Cookie import BaseCookie, SimpleCookie, CookieError
10 from pprint import pformat
11 from urllib import urlencode
12@@ -12,6 +13,7 @@
13 
14 from django.utils.datastructures import MultiValueDict, ImmutableList
15 from django.utils.encoding import smart_str, iri_to_uri, force_unicode
16+from django.utils.http import cookie_date
17 from django.http.multipartparser import MultiPartParser
18 from django.conf import settings
19 from django.core.files import uploadhandler
20@@ -373,6 +375,9 @@
21 
22     def set_cookie(self, key, value='', max_age=None, expires=None, path='/',
23                    domain=None, secure=False):
24+        # IE doesn't support the max-age property
25+        if max_age is not None and expires is None:
26+            expires = cookie_date(time.time() + max_age)
27         self.cookies[key] = value
28         if max_age is not None:
29             self.cookies[key]['max-age'] = max_age