-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Implement filter_cookies() with domain-matching and path-matching #7777
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest making some failing tests here, before doing the above updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -12,6 +12,7 @@ | |||
# 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
|
||
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.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change 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.