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

Use quote_cookie setting from ClientSession's cookiejar in tmp_cookie_jar #10093

Merged
merged 10 commits into from
Dec 17, 2024
5 changes: 5 additions & 0 deletions aiohttp/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ async def close(self) -> None:
class AbstractCookieJar(Sized, IterableBase):
"""Abstract Cookie Jar."""

@property
@abstractmethod
def quote_cookie(self) -> bool:
"""Return True if cookies should be quoted."""

@abstractmethod
def clear(self, predicate: Optional[ClearCookiePredicate] = None) -> None:
"""Clear all cookies if no predicate is passed."""
Expand Down
4 changes: 3 additions & 1 deletion aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ async def _request(
all_cookies = self._cookie_jar.filter_cookies(url)

if cookies is not None:
tmp_cookie_jar = CookieJar()
tmp_cookie_jar = CookieJar(
quote_cookie=self._cookie_jar.quote_cookie
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
)
tmp_cookie_jar.update_cookies(cookies)
req_cookies = tmp_cookie_jar.filter_cookies(url)
if req_cookies:
Expand Down
8 changes: 8 additions & 0 deletions aiohttp/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
self._expire_heap: List[Tuple[float, Tuple[str, str, str]]] = []
self._expirations: Dict[Tuple[str, str, str], float] = {}

@property
def quote_cookie(self) -> bool:
return self._quote_cookie

def save(self, file_path: PathLike) -> None:
file_path = pathlib.Path(file_path)
with file_path.open(mode="wb") as f:
Expand Down Expand Up @@ -471,6 +475,10 @@
def __len__(self) -> int:
return 0

@property
def quote_cookie(self) -> bool:
return True

Check warning on line 480 in aiohttp/cookiejar.py

View check run for this annotation

Codecov / codecov/patch

aiohttp/cookiejar.py#L480

Added line #L480 was not covered by tests
bdraco marked this conversation as resolved.
Show resolved Hide resolved

def clear(self, predicate: Optional[ClearCookiePredicate] = None) -> None:
pass

Expand Down
1 change: 0 additions & 1 deletion tests/test_client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,6 @@ async def handler(request: web.Request) -> web.Response:
assert resp_cookies["response"].value == "resp_value"


@pytest.mark.xfail(reason="Reproducer for #9336")
async def test_cookies_with_not_quoted_cookie_jar(
aiohttp_server: AiohttpServer,
) -> None:
Expand Down
Loading