Limit `FileResponse` to 100 ranges

Merged
KL
3mo ago
+24-1

Summary

  • cap FileResponse range processing at 100 entries
  • serve the complete response when a request exceeds the limit
  • test the boundary at 100 and 101 ranges

Rationale

Multipart range responses perform work for each selected range. Bounding the number keeps response handling predictable while preserving normal multi-range requests. Requests over the limit are handled as ordinary complete responses, consistent with HTTP allowing servers to ignore Range.

Tests

  • uv run pytest tests/test_responses.py -q --basetemp=/private/tmp/starlette-range-tests-final (132 passed, 2 skipped)
  • uv run ruff format --check --diff starlette/responses.py tests/test_responses.py
  • uv run ruff check starlette/responses.py tests/test_responses.py
  • uv run mypy starlette/responses.py tests/test_responses.py