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

preserve cookie escaping for old servers #1453

Merged
merged 9 commits into from
Dec 8, 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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ CHANGES

- Fix bugs related to the use of unicode hostnames #1444

- Preserve cookie quoting/escaping #1453

- FileSender will send gzipped response if gzip version available #1426

-
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Alexander Bayandin
Alexander Karpinsky
Alexander Koshevoy
Alexander Malev
Alexander Mohr
Alexander Shorin
Alexander Travov
Alexandru Mihai
Expand Down
5 changes: 4 additions & 1 deletion aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ def update_cookies(self, cookies):

for name, value in cookies.items():
if isinstance(value, http.cookies.Morsel):
c[value.key] = value.value
# Preserve coded_value
mrsl_val = value.get(value.key, http.cookies.Morsel())
mrsl_val.set(value.key, value.value, value.coded_value)
c[name] = mrsl_val
else:
c[name] = value

Expand Down
6 changes: 5 additions & 1 deletion aiohttp/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ def filter_cookies(self, request_url=URL()):
if is_not_secure and cookie["secure"]:
continue

filtered[name] = cookie.value
# It's critical we use the Morsel so the coded_value
# (based on cookie version) is preserved
mrsl_val = cookie.get(cookie.key, Morsel())
mrsl_val.set(cookie.key, cookie.value, cookie.coded_value)
filtered[name] = mrsl_val

return filtered

Expand Down
12 changes: 11 additions & 1 deletion tests/test_cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ def test_preserving_ip_domain_cookies(loop):
'Cookie: shared-cookie=first')


def test_preserving_quoted_cookies(loop):
jar = CookieJar(loop=loop, unsafe=True)
jar.update_cookies(SimpleCookie(
"ip-cookie=\"second\"; Domain=127.0.0.1;"
))
cookies_sent = jar.filter_cookies(URL("http://127.0.0.1/")).output(
header='Cookie:')
assert cookies_sent == 'Cookie: ip-cookie=\"second\"'


def test_ignore_domain_ending_with_dot(loop):
jar = CookieJar(loop=loop, unsafe=True)
jar.update_cookies(SimpleCookie("cookie=val; Domain=example.com.;"),
Expand All @@ -260,7 +270,7 @@ def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(None)

# N.B. those need to be overriden in child test cases
# N.B. those need to be overridden in child test cases
self.jar = CookieJar(loop=self.loop)

def tearDown(self):
Expand Down