Skip to content

Fix #6917: Correct Content-Length for io.StringIO with multi-byte UTF-8 #6955

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gqwtb
Copy link

@gqwtb gqwtb commented May 28, 2025

Fixes #6917

This PR resolves the incorrect Content-Length calculation when using io.StringIO as the request body. Key changes:

  1. Added special handling for io.StringIO in the super_len function
  2. Calculates the correct byte length by encoding content as UTF-8
  3. Added test cases to validate the fix

Test results:

  • Content-Length now accurately reflects byte count for io.StringIO with multi-byte characters
  • All existing tests remain passing

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.

Incorrect Content-Length header with StringIO body
1 participant