http_content_range

Enum ContentRange

source
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

source

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}));
source

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    = *CHAR

Same as parse but parses directly from the byte array

Trait Implementations§

source§

impl Clone for ContentRange

source§

fn clone(&self) -> ContentRange

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ContentRange

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for ContentRange

source§

fn eq(&self, other: &ContentRange) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for ContentRange

source§

impl Eq for ContentRange

source§

impl StructuralPartialEq for ContentRange

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.