Skip to content
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
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