Skip to content

Set content length for empty stream uploads#7452

Closed
Sean-Kenneth-Doherty wants to merge 1 commit into
psf:mainfrom
Sean-Kenneth-Doherty:codex/zero-length-stream-content-length
Closed

Set content length for empty stream uploads#7452
Sean-Kenneth-Doherty wants to merge 1 commit into
psf:mainfrom
Sean-Kenneth-Doherty:codex/zero-length-stream-content-length

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty commented May 16, 2026

Summary

  • distinguish known zero-length streams from streams with unknown length
  • send Content-Length: 0 for empty file-like uploads instead of Transfer-Encoding: chunked
  • preserve chunked uploads for generators and file descriptors whose length cannot be determined

Fixes #6294.

Testing

  • uv run --group test pytest tests/test_requests.py -k "empty_stream_with_auth or empty_file_stream or explicit_zero_content_length_stream or unknown_length_file_stream or chunked_upload_does_not_set_content_length_header or stream_with_auth_does_not_set_transfer_encoding_header"
  • uv run --group test pytest tests/test_utils.py -k super_len
  • uv run --group test pytest tests/test_lowlevel.py
  • uv run --group typecheck pyright src/requests/models.py src/requests/utils.py
  • uv run --with ruff ruff check src/requests/models.py src/requests/utils.py tests/test_requests.py
  • uv run --with ruff ruff format --check src/requests/models.py src/requests/utils.py tests/test_requests.py
  • uv run python -m compileall -q src/requests tests/test_requests.py tests/test_utils.py tests/test_lowlevel.py
  • uv run --no-sync pytest tests/test_requests.py

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty marked this pull request as ready for review May 16, 2026 23:18
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.

PUT requests for zero-byte files get 'Transfer-Encoding': 'chunked' header

2 participants