Skip to content

Commit 7b5d54a

Browse files
Cycloctanepre-commit-ci[bot]Dreamsorcerer
authored
Use quote_cookie setting from ClientSession's cookiejar in tmp_cookie_jar (aio-libs#10093)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Sam Bull <git@sambull.org>
1 parent 7c12b1a commit 7b5d54a

6 files changed

Lines changed: 19 additions & 2 deletions

File tree

CHANGES/10093.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Update :py:meth:`~aiohttp.ClientSession.request` to reuse the ``quote_cookie`` setting from ``ClientSession._cookie_jar`` when processing cookies parameter.
2+
-- by :user:`Cycloctane`.

aiohttp/abc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ async def close(self) -> None:
172172
class AbstractCookieJar(Sized, IterableBase):
173173
"""Abstract Cookie Jar."""
174174

175+
@property
176+
@abstractmethod
177+
def quote_cookie(self) -> bool:
178+
"""Return True if cookies should be quoted."""
179+
175180
@abstractmethod
176181
def clear(self, predicate: Optional[ClearCookiePredicate] = None) -> None:
177182
"""Clear all cookies if no predicate is passed."""

aiohttp/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ async def _request(
599599
all_cookies = self._cookie_jar.filter_cookies(url)
600600

601601
if cookies is not None:
602-
tmp_cookie_jar = CookieJar()
602+
tmp_cookie_jar = CookieJar(
603+
quote_cookie=self._cookie_jar.quote_cookie
604+
)
603605
tmp_cookie_jar.update_cookies(cookies)
604606
req_cookies = tmp_cookie_jar.filter_cookies(url)
605607
if req_cookies:

aiohttp/cookiejar.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ def __init__(
118118
self._expire_heap: List[Tuple[float, Tuple[str, str, str]]] = []
119119
self._expirations: Dict[Tuple[str, str, str], float] = {}
120120

121+
@property
122+
def quote_cookie(self) -> bool:
123+
return self._quote_cookie
124+
121125
def save(self, file_path: PathLike) -> None:
122126
file_path = pathlib.Path(file_path)
123127
with file_path.open(mode="wb") as f:
@@ -471,6 +475,10 @@ def __iter__(self) -> "Iterator[Morsel[str]]":
471475
def __len__(self) -> int:
472476
return 0
473477

478+
@property
479+
def quote_cookie(self) -> bool:
480+
return True
481+
474482
def clear(self, predicate: Optional[ClearCookiePredicate] = None) -> None:
475483
pass
476484

tests/test_client_session.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,6 @@ async def handler(request: web.Request) -> web.Response:
696696
assert resp_cookies["response"].value == "resp_value"
697697

698698

699-
@pytest.mark.xfail(reason="Reproducer for #9336")
700699
async def test_cookies_with_not_quoted_cookie_jar(
701700
aiohttp_server: AiohttpServer,
702701
) -> None:

tests/test_cookiejar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ async def make_jar() -> CookieJar:
831831
async def test_dummy_cookie_jar() -> None:
832832
cookie = SimpleCookie("foo=bar; Domain=example.com;")
833833
dummy_jar = DummyCookieJar()
834+
assert dummy_jar.quote_cookie is True
834835
assert len(dummy_jar) == 0
835836
dummy_jar.update_cookies(cookie)
836837
assert len(dummy_jar) == 0

0 commit comments

Comments
 (0)