Skip to content

Skip unsatisfiable ranges when at least one range is satisfiable - #1257

Open
arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:range-partially-satisfiable
Open

arturobernalg wants to merge 1 commit into
apache:mainfrom
arturobernalg:range-partially-satisfiable

Conversation

@arturobernalg

@arturobernalg arturobernalg commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

DefaultServlet returns 416 for a multi-range request as soon as one range-spec is unsatisfiable. For a 100 byte resource, Range: bytes=0-1,200-300 gets 416 although 0-1 can be served.

RFC 9110, section 14.1.1: "A valid ranges-specifier is "satisfiable" if it contains at least one range-spec that is satisfiable". Section 14.2 then says the server SHOULD send a 206 with the satisfiable range-spec(s), section 15.5.17 describes 416 as the response when none of the requested ranges are satisfiable (or when too many small or overlapping ranges are requested) and section 15.3.7.2 excludes the ranges "deemed unsatisfiable" from a multipart response.

Unsatisfiable range-specs are now skipped before validation. Invalid range-specs (last-pos less than first-pos) are still rejected and a request with no satisfiable range still gets 416.

Tested on a local Tomcat:

Range (100 byte file) before after
bytes=0-1,200-300 416 206, bytes 0-1/100
bytes=200-300,0-1 416 206, bytes 0-1/100
bytes=0-1,200-300,4-5 416 206, multipart 0-1 and 4-5
bytes=200-300 416 416
bytes=200-100,0-1 416 416

The new TestDefaultServletRangeRequests cases with a satisfiable range fail without the change; the bytes=-0 case checks that a Range header with no satisfiable range is still rejected with 416.

DefaultServlet returned 416 for a multi-range request as soon as one
range-spec was unsatisfiable, e.g. "bytes=0-1,200-300" for a 100 byte
resource. RFC 9110, section 14.1.1 defines a ranges-specifier as
satisfiable if at least one range-spec is satisfiable, section 14.2 then
says that the server SHOULD send a 206 response with the satisfiable
ranges and section 15.5.17 describes 416 as the response when none of the
requested ranges are satisfiable.

Unsatisfiable range-specs are now skipped. Invalid range-specs are still
rejected.
@arturobernalg
arturobernalg force-pushed the range-partially-satisfiable branch from 00eb103 to e7cf239 Compare November 20, 2026 16:07
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.

1 participant