Open TomerSalt opened 2 months ago
Please create a complete reproducer (or better, a failing test in a PR).
import aiohttp import asyncio
async def req(): tcp_conn = aiohttp.TCPConnector(limit=10, force_close=True) c_jar = aiohttp.CookieJar(quote_cookie=False) sess = aiohttp.ClientSession(connector=tcp_conn, cookie_jar=c_jar) cookies = {"name": "val="} resp = await sess.request(url="http://localhost:8000/", method="GET", cookies=cookies) print(resp.request_info.headers.get("Cookie")) # name="val=" await sess.close()
asyncio.run(req())
i updated the reproduce section to contain a full example
ClientSession()._request()
creates a temporary CookieJar tmp_cookie_jar
to handle the cookies from the request()
parameters. This tmp_cookie_jar
only uses default (quote_cookie=True
).
If cookies are directly passed to the manually created CookieJar
, they will remain unquoted.
import aiohttp
import asyncio
async def req():
tcp_conn = aiohttp.TCPConnector(limit=10, force_close=True)
c_jar = aiohttp.CookieJar(quote_cookie=False)
sess = aiohttp.ClientSession(connector=tcp_conn, cookie_jar=c_jar)
cookies = {"name": "val="}
c_jar.update_cookies(cookies)
resp = await sess.request(url="http://localhost:8000/", method="GET")
print(resp.request_info.headers.get("Cookie")) # name=val=
await sess.close()
asyncio.run(req())
So, perhaps we should be reusing the settings from the global CookieJar. Think you could turn that into a full test?
Describe the bug
When using an client session object with a cookie jar with the cookie quoting routine disabled the requests sent still uses quoting routine when invoking the request:
[client_reqrep.py:468] ClientRequest().update_cookies():
The variable
c
used to output the cookie is a SimpleCookie object which defaults to using the quoting routine. therefor when for example received a cookie with value such asid=!IagQHEStKHLB3DFBAufSQIeK+Olw=
the header will output asCookie: id="!IagQHEStKHLB3DFBAufSQIeK+Olw="
.A possible fix is to add a method to the CookieJar object like
is_quote_disabled()
and then in the update cookies use theself.session.is_quoting_disabled()
to specifically handle the cookie in such case. i used:To Reproduce
use the following script to reproduce:
Expected behavior
When specifying quote_cookie to False, cookie which by specifications are supposed to be quoted shouldn't be quoted because of the implicit flag.
Logs/tracebacks
Python Version
aiohttp Version
multidict Version
yarl Version
OS
Mac OS
Related component
Client
Additional context
No response
Code of Conduct