pub struct Range {
pub start: u64,
pub end: u64,
}Expand description
A byte range within a resource (start..end).
Fields§
§start: u64§end: u64Implementations§
Source§impl Range
impl Range
pub const STRING_SEPARATOR: &'static str = "String_separator"
pub const BOUNDARY: &'static str = "boundary"
pub const BYTERANGES: &'static str = "byteranges"
pub const MULTIPART: &'static str = "multipart"
pub const BYTES: &'static str = "bytes"
Sourcepub const MULTIPART_BYTERANGES_CONTENT_TYPE: &'static str = "multipart/byteranges; boundary=String_separator"
pub const MULTIPART_BYTERANGES_CONTENT_TYPE: &'static str = "multipart/byteranges; boundary=String_separator"
The fixed boundary used before 17.113.2. A part containing it broke
the framing; responses now use Range::multipart_boundary.
pub const _ERROR_NO_EMPTY_LINE_BETWEEN_CONTENT_RANGE_HEADER_AND_BODY: &'static str = "no empty line between content range headers and body"
pub const _ERROR_UNABLE_TO_PARSE_CONTENT_RANGE: &'static str = "unable to parse content-range"
pub const ERROR_START_IS_AFTER_END_CONTENT_RANGE: &'static str = "start is after end in content range"
pub const ERROR_START_IS_BIGGER_THAN_FILESIZE_CONTENT_RANGE: &'static str = "start is bigger than filesize in content range"
pub const ERROR_END_IS_BIGGER_THAN_FILESIZE_CONTENT_RANGE: &'static str = "end is bigger than filesize in content range"
pub const ERROR_MALFORMED_RANGE_HEADER_WRONG_UNIT: &'static str = "range header malformed, most likely you have an error in unit statement"
pub const ERROR_UNABLE_TO_PARSE_RANGE_START: &'static str = "unable to parse range start"
pub const ERROR_UNABLE_TO_PARSE_RANGE_END: &'static str = "unable to parse range end"
Sourcepub const MAX_RANGES: usize = 16
pub const MAX_RANGES: usize = 16
The most ranges served as parts; more become one range of the whole file (RFC 9110 §14.2 lets a server coalesce or ignore ranges).
Sourcepub fn multipart_boundary(content_range_list: &[ContentRange]) -> String
pub fn multipart_boundary(content_range_list: &[ContentRange]) -> String
The boundary for a multipart/byteranges body of these parts (#53):
derived from the parts, so the Content-Type header and
Response::generate_body
agree without passing it around, and checked not to occur in any
part (RFC 2046 §5.1.1).
Sourcepub fn multipart_content_type(content_range_list: &[ContentRange]) -> String
pub fn multipart_content_type(content_range_list: &[ContentRange]) -> String
multipart/byteranges; boundary=… for these parts.
Sourcepub fn parse_range_in_content_range(
filelength: u64,
range_str: &str,
) -> Result<Range, Error>
pub fn parse_range_in_content_range( filelength: u64, range_str: &str, ) -> Result<Range, Error>
Parse one first-last / first- / -suffix byte range against a
resource of filelength bytes (RFC 9110 §14.1.2). The returned end
is inclusive (bytes=0-0 is one byte). A last past the end is
clamped to the last byte and a suffix longer than the resource selects
all of it; a range starting at or past the end, first > last, or any
range on an empty resource is 416 Range Not Satisfiable.
pub fn parse_content_range( filepath: &str, filelength: u64, raw_range_value: &str, ) -> Result<Vec<ContentRange>, Error>
Sourcepub fn coalesce(ranges: Vec<Range>, filelength: u64) -> Vec<Range>
pub fn coalesce(ranges: Vec<Range>, filelength: u64) -> Vec<Range>
ranges (inclusive ends) as served: kept as requested when none
overlap; otherwise sorted with the overlapping ones merged — so a
response never holds more bytes than the file has; and more than
MAX_RANGES parts become the whole file.
pub fn get_content_range_list( request_uri: &str, range: &Header, ) -> Result<Vec<ContentRange>, Error>
pub fn _parse_multipart_body( cursor: &mut Cursor<&[u8]>, content_range_list: Vec<ContentRange>, ) -> Result<Vec<ContentRange>, String>
pub fn _parse_raw_content_range_header_value( unparsed_header_value: &str, ) -> Result<(i64, i64, i64), String>
pub fn _parse_content_range_header_value( header_value: String, ) -> Result<(i64, i64, i64), String>
pub fn _parse_line_as_bytes(cursor: &mut Cursor<&[u8]>) -> Vec<u8> ⓘ
pub fn _convert_bytes_array_to_string(buffer: Vec<u8>) -> String
Sourcepub fn get_content_range(body: Vec<u8>, mime_type: String) -> ContentRange
pub fn get_content_range(body: Vec<u8>, mime_type: String) -> ContentRange
Creates a ContentRange from raw bytes and a MIME type. The most common way to build a response body.
Sourcepub fn get_content_range_of_a_file(
filepath: &str,
) -> Result<ContentRange, String>
pub fn get_content_range_of_a_file( filepath: &str, ) -> Result<ContentRange, String>
Creates a ContentRange by reading a file from disk. MIME type is detected from the extension.