@@ -37,6 +37,7 @@ derive_header! {
3737}
3838
3939const ACCEPT_RANGES_BYTES : & str = "bytes" ;
40+ const ACCEPT_RANGES_NONE : & str = "none" ;
4041
4142impl AcceptRanges {
4243 /// A constructor to easily create the common `Accept-Ranges: bytes` header.
@@ -48,6 +49,16 @@ impl AcceptRanges {
4849 pub fn is_bytes ( & self ) -> bool {
4950 self . 0 . value == ACCEPT_RANGES_BYTES
5051 }
52+
53+ /// A constructor to easily create the common `Accept-Ranges: none` header.
54+ pub fn none ( ) -> Self {
55+ AcceptRanges ( HeaderValue :: from_static ( ACCEPT_RANGES_NONE ) . into ( ) )
56+ }
57+
58+ /// Check if the unit is `none`.
59+ pub fn is_none ( & self ) -> bool {
60+ self . 0 . value == ACCEPT_RANGES_NONE
61+ }
5162}
5263
5364#[ cfg( test) ]
@@ -59,6 +70,7 @@ mod tests {
5970 test_decode ( & [ s] ) . unwrap ( )
6071 }
6172
73+ // bytes
6274 #[ test]
6375 fn bytes_constructor ( ) {
6476 assert_eq ! ( accept_ranges( "bytes" ) , AcceptRanges :: bytes( ) ) ;
@@ -78,4 +90,25 @@ mod tests {
7890 fn is_bytes_method_failed_with_not_bytes_ranges ( ) {
7991 assert ! ( !accept_ranges( "dummy" ) . is_bytes( ) ) ;
8092 }
93+
94+ // none
95+ #[ test]
96+ fn none_constructor ( ) {
97+ assert_eq ! ( accept_ranges( "none" ) , AcceptRanges :: none( ) ) ;
98+ }
99+
100+ #[ test]
101+ fn is_none_method_successful_with_none_ranges ( ) {
102+ assert ! ( accept_ranges( "none" ) . is_none( ) ) ;
103+ }
104+
105+ #[ test]
106+ fn is_none_method_successful_with_none_ranges_by_constructor ( ) {
107+ assert ! ( AcceptRanges :: none( ) . is_none( ) ) ;
108+ }
109+
110+ #[ test]
111+ fn is_none_method_failed_with_not_none_ranges ( ) {
112+ assert ! ( !accept_ranges( "dummy" ) . is_none( ) ) ;
113+ }
81114}
0 commit comments