Implement filter_cookies() with domain-matching and path-matching#7777
Implement filter_cookies() with domain-matching and path-matching#7777xiangxli wants to merge 0 commit intoaio-libs:masterfrom
Conversation
aiohttp/cookiejar.py
Outdated
| d = hostname | ||
| p = request_url.path | ||
|
|
||
| cookies = list(self._cookies[(d, p)].values()) |
There was a problem hiding this comment.
Thanks for looking into this. I think there's a couple of cases still missing here.
From my understanding, we need to handle subdomains. So, we probably want d and then d.split(".", maxsplit=1) and repeat until we've checked every domain level.
And then I believe the same again for paths.
So, maybe we end up with something like:
pairs = []
while d:
p = request_url.path
while p:
pairs.append((d, p))
p = p.rsplit("/", maxsplit=1)[0]
d = d.split(".", maxsplit=1)[1]
cookies = itertools.chain.from_iterable(self._cookies[p].values() for p in pairs)
There was a problem hiding this comment.
I am checking the cases, there are a few number of failed test cases.
Will commit the changes once done.
aiohttp/cookiejar.py
Outdated
| # shared cookie, it should have max of 1 entry | ||
| shared_cookie = self._cookies.get(("", "/")) |
There was a problem hiding this comment.
Maybe I'm just forgetting. But, is there anything in the code, or something in the spec which mentions this case?
tests/test_cookiejar.py
Outdated
| jar.update_cookies(cookies) | ||
| cookies = jar.filter_cookies(URL("http://pathtest.com/")) | ||
|
|
||
| assert len(cookies) == 3 |
There was a problem hiding this comment.
We should probably assert the actual values that should be in here.
We should also test with a call that includes a subdomain and a multilevel path.
There was a problem hiding this comment.
I suggest making some failing tests here, before doing the above updates.
There was a problem hiding this comment.
Agreed, I will add some failing test cases.
|
Still interested in finishing this PR? |
@Dreamsorcerer I squeezed a few hours to finish the code, please review it when you got a change. @Dreamsorcerer |
aiohttp/helpers.py
Outdated
|
|
||
| # https://github.com/python/mypy/issues/14209 | ||
| self._name = module + "." + name # type: ignore[possibly-undefined] | ||
| self._name = module + "." + name |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable
docs/conf.py
Outdated
| # All configuration values have a default; values that are commented out | ||
| # serve to show the default. | ||
|
|
||
| import io |
Check notice
Code scanning / CodeQL
Unused import
tests/test_web_exceptions.py
Outdated
|
|
||
| def test_HTTPFound_empty_location() -> None: | ||
| with pytest.raises(ValueError): | ||
| web.HTTPFound(location="") |
Check failure
Code scanning / CodeQL
Unused exception object
tests/test_web_exceptions.py
Outdated
| web.HTTPFound(location="") | ||
|
|
||
| with pytest.raises(ValueError): | ||
| web.HTTPFound(location=None) |
Check failure
Code scanning / CodeQL
Unused exception object
tests/test_client_request.py
Outdated
| return mock.Mock() | ||
|
|
||
| connector = BaseConnector() | ||
| connector = BaseConnector(loop=loop) |
Check failure
Code scanning / CodeQL
Wrong name for an argument in a class instantiation
|
Uhh, I'm not sure what you just pushed, but now there's 150 files changed, with lots of recent changes to master being reverted... |
Could be an lagged version from master, let me fix that first. |
f36024b to
37135d2
Compare
|
PR closed by force push, continuing on the following new PR |
What do these changes do?
Implement filter_cookies() with domain-matching and path-matching on the keys, instead of testing every single cookie.
Are there changes in behavior for the user?
no
Related issue number
#7583
task 3
Checklist
CONTRIBUTORS.txtCHANGESfolder<issue_id>.<type>for example (588.bugfix)issue_idchange it to the pr id after creating the pr.feature: Signifying a new feature..bugfix: Signifying a bug fix..doc: Signifying a documentation improvement..removal: Signifying a deprecation or removal of public API..misc: A ticket has been closed, but it is not of interest to users.