HttpRange class
Represents an HTTP Range as defined in RFC 7233.
This class handles parsing, validation, and formatting of HTTP Range headers,
supporting byte ranges for partial content (HTTP 206 Partial Content responses).
Features
- Stores a single byte range with inclusive start and end positions.
- Validates that ranges are non-negative and that
end >= start. - Provides utilities to parse and format HTTP Range headers.
- Supports suffix ranges (e.g.,
bytes=-512) and multiple ranges in one header. - Can merge overlapping or adjacent ranges into consolidated ranges.
Example
final range = HttpRange(start: 0, end: 1023);
print(range.getLength()); // 1024
print(range.getContentRange(5000)); // 'bytes 0-1023/5000'
final ranges = HttpRange.parseRangeHeader('bytes=0-1023,2048-4095', 5000);
final merged = HttpRange.merge(ranges);
Constructors
Properties
Methods
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString. -
getContentRange(
int contentLength) → String - Returns the Content-Range header value for this range.
-
getEnd(
) → int - Returns the end of this range (inclusive).
-
getLength(
) → int - Returns the length of this range in bytes.
-
getStart(
) → int - Returns the start of this range (inclusive).
-
isValid(
int contentLength) → bool -
Checks if this range is valid for the given
contentLength. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
formatRangeHeader(
List< HttpRange> ranges) → String - Converts a list of HttpRange objects to an HTTP Range header value.
-
merge(
List< HttpRange> ranges) → List<HttpRange> - Merges overlapping or adjacent ranges into a consolidated list.
-
parse(
String? value) → List< HttpRange> -
Parses a
Rangeheader string into a list ofHttpRange. -
parseRangeHeader(
String rangeHeader, int contentLength) → List< HttpRange> - Parses an HTTP Range header value and returns a list of HttpRange objects.
-
parseRanges(
String rangeHeader, int contentLength) → List< HttpRange> -
Alias for
parseRangeHeader. Parses a range header string into a list ofHttpRange. -
toHeader(
List< HttpRange> ranges) → String -
Alias for
formatRangeHeader. Converts a list of ranges into a validRangeheader string.