Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add AcceptRanges none util #178

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}