diff --git a/src/common/accept_ranges.rs b/src/common/accept_ranges.rs index 3fcfc412..97075332 100644 --- a/src/common/accept_ranges.rs +++ b/src/common/accept_ranges.rs @@ -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. @@ -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)] @@ -59,6 +70,7 @@ mod tests { test_decode(&[s]).unwrap() } + // bytes #[test] fn bytes_constructor() { assert_eq!(accept_ranges("bytes"), AcceptRanges::bytes()); @@ -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()); + } }