requests icon indicating copy to clipboard operation
requests copied to clipboard

Fix stringio content length

Open killerdevildog opened this issue 5 months ago • 0 comments

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 avatar Jul 30 '25 00:07 killerdevildog