File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change
1
+ use http:: HeaderValue ;
2
+
1
3
use util:: FlatCsv ;
2
4
3
5
/// `Accept-Ranges` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-2.3)
@@ -34,9 +36,33 @@ derive_header! {
34
36
name: ACCEPT_RANGES
35
37
}
36
38
39
+ const ACCEPT_RANGES_BYTES : HeaderValue = :: HeaderValue :: from_static ( "bytes" ) ;
40
+
37
41
impl AcceptRanges {
38
42
/// A constructor to easily create the common `Accept-Ranges: bytes` header.
39
43
pub fn bytes ( ) -> Self {
40
- AcceptRanges ( :: HeaderValue :: from_static ( "bytes" ) . into ( ) )
44
+ AcceptRanges ( ACCEPT_RANGES_BYTES . into ( ) )
45
+ }
46
+
47
+ /// Check if the unit is `bytes`.
48
+ pub fn is_bytes ( & self ) -> bool {
49
+ self . 0 . value == ACCEPT_RANGES_BYTES
50
+ }
51
+ }
52
+
53
+ #[ cfg( test) ]
54
+ mod tests {
55
+ use super :: * ;
56
+
57
+ #[ test]
58
+ fn bytes ( ) {
59
+ let bytes_range = AcceptRanges :: bytes ( ) ;
60
+ assert ! ( bytes_range. is_bytes( ) ) ;
61
+ }
62
+
63
+ #[ test]
64
+ fn bytes_fails ( ) {
65
+ let none_range = AcceptRanges ( :: HeaderValue :: from_static ( "none" ) . into ( ) ) ;
66
+ assert ! ( !none_range. is_bytes( ) ) ;
41
67
}
42
68
}
You can’t perform that action at this time.
0 commit comments