requests
requests copied to clipboard
Fix stringio content length
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"