Skip to content

Skip unsatisfiable ranges instead of rejecting the whole Range set - #2703

Merged
yhirose merged 2 commits into
yhirose:masterfrom
vtxe02023274:fix/skip-unsatisfiable-ranges
Nov 30, 2026
Merged

yhirose merged 2 commits into
yhirose:masterfrom
vtxe02023274:fix/skip-unsatisfiable-ranges

Conversation

@vtxe02023274

Copy link
Copy Markdown
Contributor

range_error() answers 416 as soon as one range in the set is past the end of the body, so on the 7-byte /with-range response

Range: bytes=1-2, 10000-30000, 4-5

gets 416 instead of the two parts it can serve. RFC 9110 Section 14.1.1 says the set is satisfiable when any of its ranges is (a first-pos below the length, or a non-zero suffix-length), and Section 15.5.17 keeps 416 for when none of them are. Range parts that cannot be satisfied are left out of the 206.

The change skips an unsatisfiable range instead of returning, serves the rest, and returns 416 only when no range is left. The limits on the number of ranges and on overlapping ranges are unchanged, and only the ranges that are served count toward the overlap limit.

GetWithRangeMultipartOffsetGreaterThanContent expected 416 for bytes=-2, 10000-30000. It now expects the last two bytes (bytes 5-6/7), the same way #2615 changed bytes=-9999. New tests:

  • GetWithRangeMultipartSkipsUnsatisfiableRange: the range set above gives the same multipart body as bytes=1-2, 4-5.
  • GetWithRangeMultipartNoneSatisfiable: bytes=7-, -0 and bytes=10000-30000, 7-8 still get 416.
  • GetStreamedWithRangeSkipsUnsatisfiableRange: bytes=7-, 2-3 on a content provider gives bytes 2-3/7.

All three range-skipping tests fail with the current httplib.h (416) and pass with the change. Built with the test Makefile (g++ 11, ASan, OpenSSL) on Linux, the non-online tests pass. clang-format leaves the changed lines as they are.

vtxe02023274 and others added 2 commits November 30, 2026 12:54
RFC 9110 14.1.1: a byte-range-set is satisfiable when any of its ranges is,
and 15.5.17 keeps 416 for when none of them are. range_error() answered 416
as soon as one range started past the end of the body. Leave such ranges
out and serve the rest.
The list used for the overlap check and the list of ranges to serve always
held the same values. Also drop a test assertion that could never fail.
@yhirose
yhirose merged commit a95f17c into yhirose:master Nov 30, 2026
28 checks passed
@yhirose

yhirose commented Nov 30, 2026

Copy link
Copy Markdown
Owner

Thanks!

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.

2 participants