-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathaccept_ranges.rs
More file actions
68 lines (59 loc) · 1.5 KB
/
accept_ranges.rs
File metadata and controls
68 lines (59 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use http::HeaderValue;
use util::FlatCsv;
/// `Accept-Ranges` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-2.3)
///
/// The `Accept-Ranges` header field allows a server to indicate that it
/// supports range requests for the target resource.
///
/// # ABNF
///
/// ```text
/// Accept-Ranges = acceptable-ranges
/// acceptable-ranges = 1#range-unit / \"none\"
///
/// # Example values
/// * `bytes`
/// * `none`
/// * `unknown-unit`
/// ```
///
/// # Examples
///
/// ```
/// use headers::{AcceptRanges, HeaderMap, HeaderMapExt};
///
/// let mut headers = HeaderMap::new();
///
/// headers.typed_insert(&AcceptRanges::bytes());
/// ```
#[derive(Clone, Debug, PartialEq)]
pub struct AcceptRanges(FlatCsv);
derive_header! {
AcceptRanges(_),
name: ACCEPT_RANGES
}
const ACCEPT_RANGES_BYTES: HeaderValue = ::HeaderValue::from_static("bytes");
impl AcceptRanges {
/// A constructor to easily create the common `Accept-Ranges: bytes` header.
pub fn bytes() -> Self {
AcceptRanges(ACCEPT_RANGES_BYTES.into())
}
/// Check if the unit is `bytes`.
pub fn is_bytes(&self) -> bool {
self.0.value == ACCEPT_RANGES_BYTES
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bytes() {
let bytes_range = AcceptRanges::bytes();
assert!(bytes_range.is_bytes());
}
#[test]
fn bytes_fails() {
let none_range = AcceptRanges(::HeaderValue::from_static("none").into());
assert!(!none_range.is_bytes());
}
}