[req cookie] fix remove_cookie expires which was leading to expires computed to 0 in set_cookie and the Cookie class interpret that has no expires. Closes #2154654

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeseteff4fe02ec64
brancholdstable
phasepublic
hiddenno
parent revision#a4e667270dd4 oldstable is 3.13.X
child revision#e4ab883f07d9 backport oldstable, #1bb43e31032d [bfss, migration] fix storage migration (closes #2189206)
files modified by this revision
web/httpcache.py
web/request.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1326974222 -3600
# Thu Jan 19 12:57:02 2012 +0100
# Branch oldstable
# Node ID eff4fe02ec6478e2526ba5a7f1104f5758cdfdb6
# Parent a4e667270dd43377e04283e4272e0e8aca50e97e
[req cookie] fix remove_cookie expires which was leading to expires computed to 0 in set_cookie and the Cookie class interpret that has no expires. Closes #2154654

diff --git a/web/httpcache.py b/web/httpcache.py
@@ -21,10 +21,11 @@
1 
2  from time import mktime
3  from datetime import datetime
4 
5  # time delta usable to convert localized time to GMT time
6 +# XXX this become erroneous after a DST transition!!!
7  GMTOFFSET = - (datetime.now() - datetime.utcnow())
8 
9  class NoHTTPCacheManager(object):
10      """default cache manager: set no-cache cache control policy"""
11      def __init__(self, view):
diff --git a/web/request.py b/web/request.py
@@ -541,10 +541,14 @@
12              name, value = value, name[value].value
13          if maxage: # don't check is None, 0 may be specified
14              assert expires is None, 'both max age and expires cant be specified'
15              expires = maxage + time.time()
16          elif expires:
17 +            # we don't want to handle times before the EPOCH (cause bug on
18 +            # windows). Also use > and not >= else expires == 0 and Cookie think
19 +            # that means no expire...
20 +            assert expires + GMTOFFSET > date(1970, 1, 1)
21              expires = timegm((expires + GMTOFFSET).timetuple())
22          else:
23              expires = None
24          # make sure cookie is set on the correct path
25          cookie = Cookie(str(name), str(value), self.base_url_path(),
@@ -555,15 +559,11 @@
26          """remove a cookie by expiring it"""
27          if bwcompat is not None:
28              warn('[3.13] remove_cookie now take only a name as argument',
29                   DeprecationWarning, stacklevel=2)
30              name = bwcompat
31 -        self.set_cookie(name, '', maxage=0,
32 -                        # substracting GMTOFFSET because set_cookie
33 -                        # expects a localtime and we don't want to
34 -                        # handle times before the EPOCH
35 -                        expires=date(1970, 1, 1) - GMTOFFSET) 
36 +        self.set_cookie(name, '', maxage=0, expires=date(2000, 1, 1))
37 
38      def set_content_type(self, content_type, filename=None, encoding=None):
39          """set output content type for this request. An optional filename
40          may be given
41          """