diff --git a/aiohttp/web_reqrep.py b/aiohttp/web_reqrep.py index f3b195f779f..6e044abfc3f 100644 --- a/aiohttp/web_reqrep.py +++ b/aiohttp/web_reqrep.py @@ -511,8 +511,12 @@ def set_cookie(self, name, value, *, expires=None, self._cookies[name] = value c = self._cookies[name] + if expires is not None: c['expires'] = expires + elif c.get('expires') == 'Thu, 01 Jan 1970 00:00:00 GMT': + del c['expires'] + if domain is not None: c['domain'] = domain @@ -537,7 +541,9 @@ def del_cookie(self, name, *, domain=None, path='/'): """ # TODO: do we need domain/path here? self._cookies.pop(name, None) - self.set_cookie(name, '', max_age=0, domain=domain, path=path) + self.set_cookie(name, '', max_age=0, + expires="Thu, 01 Jan 1970 00:00:00 GMT", + domain=domain, path=path) @property def content_length(self): diff --git a/docs/web_reference.rst b/docs/web_reference.rst index 79368a98f73..5d781fab6e1 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -504,6 +504,11 @@ StreamResponse :param str path: optional cookie path, ``'/'`` by default + .. versionchanged:: 0.23 + + Fixed cookie expiration support for + Internet Explorer (version less than 11). + .. attribute:: content_length *Content-Length* for outgoing response. diff --git a/tests/test_web_response.py b/tests/test_web_response.py index f434caf8981..b554fbf6890 100644 --- a/tests/test_web_response.py +++ b/tests/test_web_response.py @@ -453,7 +453,8 @@ def test_response_cookies(): 'Set-Cookie: name=another_other_value; Max-Age=10; Path=/') resp.del_cookie('name') - expected = 'Set-Cookie: name=("")?; Max-Age=0; Path=/' + expected = ('Set-Cookie: name=("")?; ' + 'expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; Path=/') assert re.match(expected, str(resp.cookies)) resp.set_cookie('name', 'value', domain='local.host') @@ -491,7 +492,8 @@ def test_response_cookie__issue_del_cookie(): assert str(resp.cookies) == '' resp.del_cookie('name') - expected = 'Set-Cookie: name=("")?; Max-Age=0; Path=/' + expected = ('Set-Cookie: name=("")?; ' + 'expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; Path=/') assert re.match(expected, str(resp.cookies)) @@ -502,6 +504,7 @@ def test_cookie_set_after_del(): resp.set_cookie('name', 'val') # check for Max-Age dropped expected = 'Set-Cookie: name=val; Path=/' + print(expected) assert str(resp.cookies) == expected