pub enum ContentRange {
Bytes(ContentRangeBytes),
UnboundBytes(ContentRangeUnbound),
Unsatisfied(ContentRangeUnsatisfied),
}Expand description
HTTP Content-Range response header representation.
Variants§
Bytes(ContentRangeBytes)
Regular bytes range response with status 206
UnboundBytes(ContentRangeUnbound)
Regular bytes range response with status 206
Unsatisfied(ContentRangeUnsatisfied)
Server response with status 416
Implementations§
Source§impl ContentRange
impl ContentRange
Sourcepub fn parse(header: &str) -> Option<ContentRange>
pub fn parse(header: &str) -> Option<ContentRange>
Parses Content-Range HTTP header string as per RFC 7233.
header is the HTTP Content-Range header (e.g. bytes 0-9/30).
This parser is a bit more lenient than the official RFC, it allows spaces and tabs between everything. See https://httpwg.org/specs/rfc7233.html#rfc.section.4.2
assert_eq!(ContentRange::parse("bytes 42-69/420").unwrap(),
ContentRange::Bytes(ContentRangeBytes{first_byte: 42, last_byte: 69, complete_length: 420}));
// complete_length is unknown
assert_eq!(ContentRange::parse("bytes 42-69/*").unwrap(),
ContentRange::UnboundBytes(ContentRangeUnbound{first_byte: 42, last_byte: 69}));
// response is unsatisfied
assert_eq!(ContentRange::parse("bytes */420").unwrap(),
ContentRange::Unsatisfied(ContentRangeUnsatisfied{complete_length: 420}));Sourcepub fn parse_bytes(header: &[u8]) -> Option<ContentRange>
pub fn parse_bytes(header: &[u8]) -> Option<ContentRange>
From https://httpwg.org/specs/rfc7233.html#rfc.section.4.2 Valid bytes responses: Content-Range: bytes 42-1233/1234 Content-Range: bytes 42-1233/* Content-Range: bytes */1233
Content-Range = byte-content-range
/ other-content-range
byte-content-range = bytes-unit SP
( byte-range-resp / unsatisfied-range )
byte-range-resp = byte-range "/" ( complete-length / "*" )
byte-range = first-byte-pos "-" last-byte-pos
unsatisfied-range = "*/" complete-length
complete-length = 1*DIGIT
other-content-range = other-range-unit SP other-range-resp
other-range-resp = *CHARSame as parse but parses directly from the byte array
Trait Implementations§
Source§impl Clone for ContentRange
impl Clone for ContentRange
Source§fn clone(&self) -> ContentRange
fn clone(&self) -> ContentRange
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ContentRange
impl Debug for ContentRange
Source§impl FromStr for ContentRange
impl FromStr for ContentRange
Source§impl PartialEq for ContentRange
impl PartialEq for ContentRange
Source§impl TryFrom<&[u8]> for ContentRange
impl TryFrom<&[u8]> for ContentRange
Source§impl TryFrom<&str> for ContentRange
impl TryFrom<&str> for ContentRange
impl Copy for ContentRange
impl Eq for ContentRange
impl StructuralPartialEq for ContentRange
Auto Trait Implementations§
impl Freeze for ContentRange
impl RefUnwindSafe for ContentRange
impl Send for ContentRange
impl Sync for ContentRange
impl Unpin for ContentRange
impl UnwindSafe for ContentRange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more