Repository navigation
Fix 416 for suffix Range on zero-length files - #3927
Open
tony1233200 wants to merge 2 commits into
Open
tony1233200 wants to merge 2 commits into
tony1233200 wants to merge 2 commits into
Conversation
StaticFileHandler rejected a non-zero suffix range (e.g. bytes=-5) on a zero-length file with 416 because the clamped start (0) was equal to the size (0). Per RFC 9110 14.1.1 a suffix range longer than the representation is satisfiable, so skip the start >= size check for suffix ranges and return the whole (empty) representation with 200. Fixes tornadoweb#3926.
Member
|
The new tests (and mypy) are failing in CI |
Author
|
Thanks for flagging this — both failures traced to the same oversight:
Both fixes are pushed in a3e5ef6; CI should be green now. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3926.
StaticFileHandleransweredRange: bytes=-5on a zero-length file with 416: the suffix start was clamped to 0, and0 >= size (0)tripped the unsatisfiable-range check. Per RFC 9110 section 14.1.1 a suffix range longer than the representation is satisfiable (the entire representation is used), so thestart >= sizecheck is now skipped for suffix ranges. A request withbytes=-5on an empty file now gets the same 200 with an empty body as a request with noRangeheader.bytes=0-on an empty file still returns 416, andbytes=-0still returns 416 (zero-length suffix), as before.Repro (before the fix
bytes=-5returned 416, after it returns 200 with an empty body):Tests: added
test_static_with_range_suffix_on_empty_file(200, empty body,Content-Length: 0, noContent-Range) andtest_static_unsatisfiable_range_start_on_empty_file(416 forbytes=0-) next to the existingbytes=-0test, with a new empty fixturetornado/test/static/empty.txt. All 11 range tests inStaticFileTestpass, as do the fullStaticFileTest(40 tests) andhttputil_testsuites;blackandflake8are clean.