|
YAACC - UPNP Client and Server
|
Turns the Range header of a request into the one answer a single-range server gives: status 200, 206 or 416, the bytes to send and the Content-Range text.
More...

Classes | |
| class | Range |
| One requested range, immutable. | |
| class | Result |
| The answer for one request, immutable. | |
Static Public Member Functions | |
| static List< Range > | parseHeader (String rangeHeader) |
Parses the raw Range header value. | |
| static Result | resolve (List< Range > requested, long totalLength) |
| Resolves the requested ranges against the resource length. | |
Turns the Range header of a request into the one answer a single-range server gives: status 200, 206 or 416, the bytes to send and the Content-Range text.
Plain Java (no android.*), long arithmetic only, and nothing here throws for any input: the header is attacker-controlled.
Decisions (RFC 9110 section 14):
Range header gives 200 with the whole resource and no Content-Range. "Not usable" means: null, empty, a unit other than bytes (compared ignoring ASCII case), or a syntactically invalid header (a malformed piece, a range whose last position is below its first, a header longer than MAX_HEADER_LENGTH). An invalid header is IGNORED, never answered with 416. bytes */len: the first position is at or beyond the length, a suffix of length 0, or any range on an empty resource (also a suffix: nothing to select). bytes 0-999/1000). A last position at or beyond the length is clipped to length - 1; a suffix longer than the resource gives everything from 0. long saturate at Long#MAX_VALUE (they only ever mean "far beyond any length"); they never throw. length() is -1. 0-99, after =) makes the header invalid. Digits are ASCII only, leading zeros are fine.
|
static |
Parses the raw Range header value.
Never throws, never returns null.
| rangeHeader | the header value, may be null |
bytes, a header longer than MAX_HEADER_LENGTH, a header without any range (bytes=, bytes=,) and ANY syntactically invalid piece (the whole header is then ignored, e.g. bytes=0-9,x or bytes=10-5). Numbers that overflow long saturate at Long#MAX_VALUE.
|
static |
Resolves the requested ranges against the resource length.
Never throws.
| requested | the ranges from parseHeader(String); null or empty means no range (200, whole resource); more than one range, a null element or an invalid range (Range#isValid()) also gives 200 with the whole resource |
| totalLength | the length of the resource in bytes; negative means unknown (200) |