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

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 calls for a 206 with the satisfiable range-spec(s), section 15.5.17 limits 416 to the case where none of the ranges are satisfiable and section 15.3.7.2 excludes unsatisfiable ranges 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

Tests added to TestDefaultServletRangeRequests fail without the change.

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
calls for a 206 response with the satisfiable ranges and section 15.5.17
limits 416 to the case where none of the ranges are satisfiable.

Unsatisfiable range-specs are now skipped. Invalid range-specs are still
rejected.
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