-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Support Reusable Request Bodies and Improve Payload Handling #11017
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #11017 +/- ##
==========================================
+ Coverage 98.75% 98.81% +0.06%
==========================================
Files 129 129
Lines 40080 41308 +1228
Branches 2204 2226 +22
==========================================
+ Hits 39580 40819 +1239
+ Misses 348 339 -9
+ Partials 152 150 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I'm going to try to get this merged tonight so its not blocking Sam's PRs. I keep finding small nits though |
Backport to 3.12: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 1c01726 on top of patchback/backports/3.12/1c0172666f26e11e99850198154336390fdacb09/pr-11017 Backporting merged PR #11017 into master
🤖 @patchback |
Backport to 3.13: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 1c01726 on top of patchback/backports/3.13/1c0172666f26e11e99850198154336390fdacb09/pr-11017 Backporting merged PR #11017 into master
🤖 @patchback |
(cherry picked from commit 1c01726)
(cherry picked from commit 1c01726)
(cherry picked from commit 1c01726)
(cherry picked from commit 1c01726)
…d Improve Payload Handling (#11019)
…d Improve Payload Handling (#11018)
Overview
This PR enhances aiohttp's payload handling system to support reusable request bodies, addressing a common pain point where payloads could only be used once. The changes enable retry mechanisms and middleware to work with request bodies without consuming them permanently.
Fixes #5577 - Digest authentication now works with request bodies (previously failed with "payload consumed" errors)
Fixes #5530 - Request bodies can now be reused in retry scenarios without "attempt to read body twice" errors
Replaces and closes #9201 - Thanks @GLGDLY
Key Changes
1. Reusable Payload Support
consumed
andautoclose
properties to track payload stateas_bytes()
method for safe payload content retrievalAsyncIterablePayload
to enable reuse2. Enhanced Payload Classes
autoclose=True
since bytes are immutable and reusablesize
property usingcached_property
3. ClientRequest Improvements
update_body()
method for middleware use to safely update request bodies.body
setter cleans up all current payload types, and documented that using the setter is the wrong way to do this as we want consumers of the API to call the asyncupdate_body()
method so we can safely clean up any type of new payloads in the future. A resource warning will be thrown if they manually set the body using the setter instead of callingupdate_body()
, as this is likely to leak in the future.4. Middleware Enhancements
5. Resource Management
close()
methods for all payload typesBenefits
Testing
Breaking Changes
None - all changes are backward compatible. Existing code will continue to work as before.
Documentation