Skip to content

Conversation

killerdevildog
Copy link
Contributor

fix(utils): correct Content-Length for io.StringIO bodies (#6917)

  • Add special handling for io.StringIO in super_len() function
  • Calculate byte length by encoding StringIO content as UTF-8
  • Preserve stream position to avoid surprising users
  • Fixes incorrect Content-Length header when StringIO contains multi-byte UTF-8 characters
  • Test multi-byte UTF-8 characters (💩, 🚀, 🎉)
  • Test position preservation after super_len call
  • Test partial read scenarios
  • Test PreparedRequest Content-Length header
  • Test consistency with str and bytes behavior
  • All tests verify correct byte-length calculation"

killerdevildog and others added 5 commits July 17, 2025 19:10
- Updated Session.request() docstring to match requests.request()
- Changed 'How long to wait' to 'How many seconds to wait'
- Fixes inconsistency in timeout documentation

Fixes psf#6813
- Add special handling for io.StringIO in super_len() function
- Calculate byte length by encoding StringIO content as UTF-8
- Preserve stream position to avoid surprising users
- Fixes incorrect Content-Length header when StringIO contains multi-byte UTF-8 characters
- Test multi-byte UTF-8 characters (💩, 🚀, 🎉)
- Test position preservation after super_len call
- Test partial read scenarios
- Test PreparedRequest Content-Length header
- Test consistency with str and bytes behavior
- All tests verify correct byte-length calculation
- Expand compressed logic into clearer if/else blocks
- Add explanatory comment for remaining bytes calculation
- Maintain same functionality with better code structure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant