Skip to content

Commit

Permalink
Merge pull request #613 from neumond/master
Browse files Browse the repository at this point in the history
Avoid sending cookie attributes in Cookie header
  • Loading branch information
asvetlov committed Dec 18, 2015
2 parents 3f45203 + b19b036 commit 14f0441
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 1 addition & 2 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ def update_cookies(self, cookies):

for name, value in cookies:
if isinstance(value, http.cookies.Morsel):
# use dict method because SimpleCookie class modifies value
dict.__setitem__(c, name, value)
c[value.key] = value.value
else:
c[name] = value

Expand Down
24 changes: 24 additions & 0 deletions tests/test_client_functional_oldstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,30 @@ def test_cookies(self):
self.assertIn(b'"Cookie": "test1=123; test3=456"', bytes(content))
r.close()

def test_morsel_with_attributes(self):
with test_utils.run_server(self.loop, router=Functional) as httpd:
c = http.cookies.Morsel()
c.set('test3', '456', '456')
c['httponly'] = True
c['secure'] = True
c['max-age'] = 1000

r = self.loop.run_until_complete(
client.request(
'get', httpd.url('method', 'get'), loop=self.loop,
cookies={'test2': c}))
self.assertEqual(r.status, 200)

content = self.loop.run_until_complete(r.content.read())
# No cookie attribute should pass here
# they are only used as filters
# whether to send particular cookie or not.
# E.g. if cookie expires it just becomes thrown away.
# Server who sent the cookie with some attributes
# already knows them, no need to send this back again and again
self.assertIn(b'"Cookie": "test3=456"', bytes(content))
r.close()

@mock.patch('aiohttp.client_reqrep.client_logger')
def test_set_cookies(self, m_log):
with test_utils.run_server(self.loop, router=Functional) as httpd:
Expand Down

0 comments on commit 14f0441

Please sign in to comment.