Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IE support for cookie deletion. #994

Merged
merged 5 commits into from
Jul 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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))


Expand All @@ -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


Expand Down