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

Implement filter_cookies() with domain-matching and path-matching #7944

Merged
merged 31 commits into from
Jan 21, 2024

Conversation

xiangxli
Copy link
Contributor

@xiangxli xiangxli commented Dec 4, 2023

What do these changes do?

Implement filter_cookies() with domain-matching and path-matching on the keys, instead of testing every single cookie.

Fork from the below PR, force push caused it to be closed.
#7777

Are there changes in behavior for the user?

no

Related issue number

#7583

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .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.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Dec 4, 2023
@xiangxli
Copy link
Contributor Author

xiangxli commented Dec 4, 2023

@Dreamsorcerer Hey buddy. The PR 7777 was closed by force push, creating this new PR to continue.

aiohttp/cookiejar.py Outdated Show resolved Hide resolved
aiohttp/cookiejar.py Outdated Show resolved Hide resolved
aiohttp/cookiejar.py Outdated Show resolved Hide resolved
aiohttp/cookiejar.py Outdated Show resolved Hide resolved
aiohttp/cookiejar.py Outdated Show resolved Hide resolved
aiohttp/cookiejar.py Outdated Show resolved Hide resolved
aiohttp/cookiejar.py Outdated Show resolved Hide resolved
CHANGES/7583.feature Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2670e7b) 97.42% compared to head (ac55d64) 97.49%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7944      +/-   ##
==========================================
+ Coverage   97.42%   97.49%   +0.07%     
==========================================
  Files         107      107              
  Lines       32601    32587      -14     
  Branches     3799     3799              
==========================================
+ Hits        31760    31770      +10     
+ Misses        634      614      -20     
+ Partials      207      203       -4     
Flag Coverage Δ
CI-GHA 97.41% <100.00%> (+0.06%) ⬆️
OS-Linux 97.07% <100.00%> (+0.13%) ⬆️
OS-Windows 95.57% <100.00%> (+0.04%) ⬆️
OS-macOS 96.70% <100.00%> (-0.18%) ⬇️
Py-3.10.11 95.50% <100.00%> (?)
Py-3.10.13 96.88% <100.00%> (-0.01%) ⬇️
Py-3.11.7 96.53% <100.00%> (+0.11%) ⬆️
Py-3.12.1 96.66% <100.00%> (?)
Py-3.8.10 95.46% <100.00%> (-0.01%) ⬇️
Py-3.8.18 96.81% <100.00%> (-0.01%) ⬇️
Py-3.9.13 95.46% <100.00%> (-0.01%) ⬇️
Py-3.9.18 96.85% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.15 96.40% <100.00%> (?)
VM-macos 96.70% <100.00%> (-0.18%) ⬇️
VM-ubuntu 97.07% <100.00%> (+0.13%) ⬆️
VM-windows 95.57% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Dreamsorcerer
Copy link
Member

@bdraco Made a few more optimisations after looking at codecov. Would be good if you can double check them.

@bdraco
Copy link
Member

bdraco commented Jan 20, 2024

Starting my day soon, I'll be at my desk in about an hour run through everything

@bdraco
Copy link
Member

bdraco commented Jan 20, 2024

This looks good. I'll put it on production

@bdraco
Copy link
Member

bdraco commented Jan 20, 2024

Nothing obvious broke on production.

Will do a py-spy to look at the flow ...

@bdraco
Copy link
Member

bdraco commented Jan 20, 2024

Looks like py-spy won't work here as its too fast now to get any samples compared to the rest of the program.

Will do cProfile instead

@bdraco
Copy link
Member

bdraco commented Jan 20, 2024

I think this is good to go.

@Dreamsorcerer Dreamsorcerer merged commit 54ceb6f into aio-libs:master Jan 21, 2024
30 of 34 checks passed
Copy link
Contributor

patchback bot commented Jan 21, 2024

Backport to 3.10: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 54ceb6f on top of patchback/backports/3.10/54ceb6fd48ff4c4add2107a460376fc72c2b76e9/pr-7944

Backporting merged PR #7944 into master

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/aio-libs/aiohttp.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/3.10/54ceb6fd48ff4c4add2107a460376fc72c2b76e9/pr-7944 upstream/3.10
  4. Now, cherry-pick PR Implement filter_cookies() with domain-matching and path-matching #7944 contents into that branch:
    $ git cherry-pick -x 54ceb6fd48ff4c4add2107a460376fc72c2b76e9
    If it'll yell at you with something like fatal: Commit 54ceb6fd48ff4c4add2107a460376fc72c2b76e9 is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 54ceb6fd48ff4c4add2107a460376fc72c2b76e9
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR Implement filter_cookies() with domain-matching and path-matching #7944 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/3.10/54ceb6fd48ff4c4add2107a460376fc72c2b76e9/pr-7944
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

Dreamsorcerer pushed a commit that referenced this pull request Jan 21, 2024
)

---------

Co-authored-by: Sam Bull <git@sambull.org>
Co-authored-by: J. Nick Koston <nick@koston.org>
(cherry picked from commit 54ceb6f)
Dreamsorcerer added a commit that referenced this pull request Jan 21, 2024
)

(#7944)

---------

Co-authored-by: Sam Bull <git@sambull.org>
Co-authored-by: J. Nick Koston <nick@koston.org>
(cherry picked from commit 54ceb6f)

---------

Co-authored-by: xiangxli <xiang_xli@qq.com>
bdraco added a commit that referenced this pull request Jul 25, 2024
…_cookies (#8537)

**This is a backport of PR #8535 as merged into master
(7108d64).**


<!-- Thank you for your contribution! -->

## What do these changes do?
 
Small speed up to cookiejar

Using `str.format` is ~16% faster than the lambda

followup to
#7944 (comment). I
was hoping to use `join` there but later realized `str.format` will take
`*args`

## Are there changes in behavior for the user?

no
## Is it a substantial burden for the maintainers to support this?

no


benchmark
```python
import timeit
import itertools

_FORMAT_PATH = "{0}/{1}".format

path = "lolonglonglonglonglonglongng/path/to/a/file"

print(
    timeit.timeit(
        'itertools.accumulate(path.split("/"), _FORMAT_PATH)', globals=globals()
    )
)


print(
    timeit.timeit(
        'itertools.accumulate(path.split("/"), lambda x, y: f"{x}/{y}")',
        globals=globals(),
    )
)
```

Co-authored-by: J. Nick Koston <nick@koston.org>
slovdahl added a commit to slovdahl/pybravia that referenced this pull request Aug 16, 2024
aiohttp 3.10 and more specifically aio-libs/aiohttp#7944 changed the way cookies are handled. Previously, the domain did not have to be part of the cookie jar for a cookie to be used. As this was changed in 3.10, we now need to pass in the response URL when updating the cookie jar, otherwise the domain will not be part of the stored cookie, and consequently will not be used for the next request.

Fixes home-assistant/core#123310.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants