Skip to content

Commit

Permalink
feat: add AcceptRanges none util
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored and seanmonstar committed Mar 26, 2024
1 parent 0a258a0 commit 2ffcd7a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/common/accept_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ derive_header! {
}

const ACCEPT_RANGES_BYTES: &str = "bytes";
const ACCEPT_RANGES_NONE: &str = "none";

impl AcceptRanges {
/// A constructor to easily create the common `Accept-Ranges: bytes` header.
Expand All @@ -48,6 +49,16 @@ impl AcceptRanges {
pub fn is_bytes(&self) -> bool {
self.0.value == ACCEPT_RANGES_BYTES
}

/// A constructor to easily create the common `Accept-Ranges: none` header.
pub fn none() -> Self {
AcceptRanges(HeaderValue::from_static(ACCEPT_RANGES_NONE).into())
}

/// Check if the unit is `none`.
pub fn is_none(&self) -> bool {
self.0.value == ACCEPT_RANGES_NONE
}
}

#[cfg(test)]
Expand All @@ -59,6 +70,7 @@ mod tests {
test_decode(&[s]).unwrap()
}

// bytes
#[test]
fn bytes_constructor() {
assert_eq!(accept_ranges("bytes"), AcceptRanges::bytes());
Expand All @@ -78,4 +90,25 @@ mod tests {
fn is_bytes_method_failed_with_not_bytes_ranges() {
assert!(!accept_ranges("dummy").is_bytes());
}

// none
#[test]
fn none_constructor() {
assert_eq!(accept_ranges("none"), AcceptRanges::none());
}

#[test]
fn is_none_method_successful_with_none_ranges() {
assert!(accept_ranges("none").is_none());
}

#[test]
fn is_none_method_successful_with_none_ranges_by_constructor() {
assert!(AcceptRanges::none().is_none());
}

#[test]
fn is_none_method_failed_with_not_none_ranges() {
assert!(!accept_ranges("dummy").is_none());
}
}

0 comments on commit 2ffcd7a

Please sign in to comment.