Conversation
CodSpeed Performance ReportMerging #9732 will not alter performanceComparing Summary
|
|
Also #6915. There are some examples in there of different use cases which should work when this is complete. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9732 +/- ##
==========================================
+ Coverage 98.71% 98.74% +0.02%
==========================================
Files 125 127 +2
Lines 37894 38520 +626
Branches 2094 2123 +29
==========================================
+ Hits 37407 38036 +629
+ Misses 338 336 -2
+ Partials 149 148 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
Since we're generally happy with the design now (as discussed on Matrix), I'll go ahead and merge this to unblock the follow-up work. Any further adjustments can be handled in a separate PR. |
Backport to 3.12: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 1e911ea on top of patchback/backports/3.12/1e911eaf23091b42cc374547ff9bf692debf9720/pr-9732 Backporting merged PR #9732 into master
🤖 @patchback |
|
Didn't think I would be that lucky that it wouldn't conflict 😄 |
Co-authored-by: Sam Bull <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit 1e911ea)
Co-authored-by: Sam Bull <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
|
Thanks for the review. I'll clean this up between sprint work. |
Summary
This PR introduces middleware support for the aiohttp client, allowing users to intercept and modify requests and responses. This brings the client API closer to parity with the server API and enables powerful use cases like authentication, logging, retries, and request/response modification.
Key Changes
Core Implementation
Added
aiohttp.client_middlewaresmodule with:ClientMiddlewareTypetype alias for middleware functionsClientHandlerTypetype alias for request handlersbuild_client_middlewares()function to chain middlewares efficientlyModified
ClientSessionto acceptmiddlewaresparameter:_middlewaresattribute to store session middlewaresAdded
sessionattribute toClientRequest:Documentation
client_advanced.rst:Tests
test_client_middleware.py(~1100 lines):Features Enabled
Example Usage
Technical Details
partialorupdate_wrapperto reduce overheadBreaking Changes
None. This is a backwards-compatible addition.
Related Issues
aiohttp.client#434 - Add middleware for client requests