Respect file cursor positions when calculating raw content length

Merged
KL
2mo ago
+64-2

Calculate Content-Length for content=fileobj from the current cursor, using zero at or past EOF and chunked transfer when the length cannot be determined. Use logical seek/tell measurements so transformed streams do not mix compressed file sizes with decompressed offsets; this can scan compressed streams during length detection. Leave multipart rewind behavior unchanged.

Add five focused public-API regression cases: a partial file, EOF, past EOF, a gzip stream, and a non-seekable pipe. Keep the existing BytesIO test and the multipart length assertion.

Validation on Python 3.15: 1,740 tests passed, 1 skipped, and 5 network tests excluded. Ruff and mypy pass; all changed files have 100% coverage.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.