diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index d54c64f28cf..51205ec89d5 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -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 diff --git a/tests/test_client_functional_oldstyle.py b/tests/test_client_functional_oldstyle.py index 7b0d0b2868f..88f29c892b8 100644 --- a/tests/test_client_functional_oldstyle.py +++ b/tests/test_client_functional_oldstyle.py @@ -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: