File tree 16 files changed +79
-16
lines changed
16 files changed +79
-16
lines changed Original file line number Diff line number Diff line change @@ -21,17 +21,3 @@ header! {
21
21
test_header!( test1, vec![ b"iso-8859-5, unicode-1-1;q=0.8" ] ) ;
22
22
}
23
23
}
24
-
25
-
26
- #[ test]
27
- fn test_parse_header ( ) {
28
- use header:: { self , q} ;
29
- let a: AcceptCharset = header:: Header :: parse_header (
30
- [ b"iso-8859-5, iso-8859-6;q=0.8" . to_vec ( ) ] . as_ref ( ) ) . unwrap ( ) ;
31
- let b = AcceptCharset ( vec ! [
32
- QualityItem { item: Charset :: Iso_8859_5 , quality: q( 1.0 ) } ,
33
- QualityItem { item: Charset :: Iso_8859_6 , quality: q( 0.8 ) } ,
34
- ] ) ;
35
- assert_eq ! ( format!( "{}" , a) , format!( "{}" , b) ) ;
36
- assert_eq ! ( a, b) ;
37
- }
Original file line number Diff line number Diff line change @@ -5,4 +5,6 @@ header! {
5
5
#[ doc="The `Access-Control-Max-Age` header indicates how long the results of a" ]
6
6
#[ doc="preflight request can be cached in a preflight result cache." ]
7
7
( AccessControlMaxAge , "Access-Control-Max-Age" ) => [ u32 ]
8
- }
8
+
9
+ test_access_control_max_age { }
10
+ }
Original file line number Diff line number Diff line change @@ -7,4 +7,6 @@ header! {
7
7
#[ doc="The `Access-Control-Request-Method` header indicates which method will be" ]
8
8
#[ doc="used in the actual request as part of the preflight request." ]
9
9
( AccessControlRequestMethod , "Access-Control-Request-Method" ) => [ Method ]
10
+
11
+ test_access_control_request_method { }
10
12
}
Original file line number Diff line number Diff line change @@ -16,6 +16,11 @@ header! {
16
16
#[ doc="Content-Length = 1*DIGIT" ]
17
17
#[ doc="```" ]
18
18
( ContentLength , "Content-Length" ) => [ u64 ]
19
+
20
+ test_content_length {
21
+ // Testcase from RFC
22
+ test_header!( test1, vec![ b"3495" ] , Some ( HeaderField ( 3495 ) ) ) ;
23
+ }
19
24
}
20
25
21
26
bench_header ! ( bench, ContentLength , { vec![ b"42349984" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,15 @@ header! {
17
17
#[ doc="Content-Type = media-type" ]
18
18
#[ doc="```" ]
19
19
( ContentType , "Content-Type" ) => [ Mime ]
20
+
21
+ test_content_type {
22
+ test_header!(
23
+ test1,
24
+ // FIXME: Should be b"text/html; charset=ISO-8859-4" but mime crate lowercases
25
+ // the whole value so parsing and formatting the value gives a different result
26
+ vec![ b"text/html; charset=iso-8859-4" ] ,
27
+ Some ( HeaderField ( Mime ( TopLevel :: Text , SubLevel :: Html , vec![ ( Attr :: Charset , Value :: Ext ( "iso-8859-4" . to_string( ) ) ) ] ) ) ) ) ;
28
+ }
20
29
}
21
30
22
31
bench_header ! ( bench, ContentType , { vec![ b"application/json; charset=utf-8" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ header! {
11
11
#[ doc="Date = HTTP-date" ]
12
12
#[ doc="```" ]
13
13
( Date , "Date" ) => [ HttpDate ]
14
+
15
+ test_date {
16
+ test_header!( test1, vec![ b"Tue, 15 Nov 1994 08:12:31 GMT" ] ) ;
17
+ }
14
18
}
15
19
16
20
bench_header ! ( imf_fixdate, Date , { vec![ b"Sun, 07 Nov 1994 08:48:37 GMT" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ header! {
18
18
#[ doc="ETag = entity-tag" ]
19
19
#[ doc="```" ]
20
20
( ETag , "ETag" ) => [ EntityTag ]
21
+
22
+ test_etag {
23
+ test_header!( test1, vec![ b"\" xyzzy\" " ] , Some ( HeaderField ( EntityTag :: new( false , "xyzzy" . to_string( ) ) ) ) ) ;
24
+ test_header!( test2, vec![ b"W/\" xyzzy\" " ] , Some ( HeaderField ( EntityTag :: new( true , "xyzzy" . to_string( ) ) ) ) ) ;
25
+ test_header!( test3, vec![ b"\" \" " ] , Some ( HeaderField ( EntityTag :: new( false , "" . to_string( ) ) ) ) ) ;
26
+ }
21
27
}
22
28
23
29
#[ cfg( test) ]
Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ header! {
15
15
#[ doc="Expires = HTTP-date" ]
16
16
#[ doc="```" ]
17
17
( Expires , "Expires" ) => [ HttpDate ]
18
+
19
+ test_expires {
20
+ // Testcase from RFC
21
+ test_header!( test1, vec![ b"Thu, 01 Dec 1994 16:00:00 GMT" ] ) ;
22
+ }
18
23
}
19
24
20
25
bench_header ! ( imf_fixdate, Expires , { vec![ b"Sun, 07 Nov 1994 08:48:37 GMT" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ header! {
15
15
#[ doc="If-Unmodified-Since = HTTP-date" ]
16
16
#[ doc="```" ]
17
17
( IfModifiedSince , "If-Modified-Since" ) => [ HttpDate ]
18
+
19
+ test_if_modified_since {
20
+ // Testcase from RFC
21
+ test_header!( test1, vec![ b"Sat, 29 Oct 1994 19:43:31 GMT" ] ) ;
22
+ }
18
23
}
19
24
20
25
bench_header ! ( imf_fixdate, IfModifiedSince , { vec![ b"Sun, 07 Nov 1994 08:48:37 GMT" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ header! {
15
15
#[ doc="If-Unmodified-Since = HTTP-date" ]
16
16
#[ doc="```" ]
17
17
( IfUnmodifiedSince , "If-Unmodified-Since" ) => [ HttpDate ]
18
+
19
+ test_if_unmodified_since {
20
+ // Testcase from RFC
21
+ test_header!( test1, vec![ b"Sat, 29 Oct 1994 19:43:31 GMT" ] ) ;
22
+ }
18
23
}
19
24
20
25
bench_header ! ( imf_fixdate, IfUnmodifiedSince , { vec![ b"Sun, 07 Nov 1994 08:48:37 GMT" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ header! {
13
13
#[ doc="Expires = HTTP-date" ]
14
14
#[ doc="```" ]
15
15
( LastModified , "Last-Modified" ) => [ HttpDate ]
16
+
17
+ test_last_modified {
18
+ // Testcase from RFC
19
+ test_header!( test1, vec![ b"Sat, 29 Oct 1994 19:43:31 GMT" ] ) ; }
16
20
}
17
21
18
22
bench_header ! ( imf_fixdate, LastModified , { vec![ b"Sun, 07 Nov 1994 08:48:37 GMT" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ header! {
14
14
// TODO: Use URL
15
15
( Location , "Location" ) => [ String ]
16
16
17
+ test_location {
18
+ // Testcase from RFC
19
+ test_header!( test1, vec![ b"/People.html#tim" ] ) ;
20
+ test_header!( test2, vec![ b"http://www.example.net/index.html" ] ) ;
21
+ }
22
+
17
23
}
18
24
19
25
bench_header ! ( bench, Location , { vec![ b"http://foo.com/hello:3000" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -202,7 +202,7 @@ macro_rules! header {
202
202
}
203
203
} ;
204
204
// Single value header
205
- ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => [ $value: ty] ) => {
205
+ ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => [ $value: ty] $tm : ident { $ ( $tf : item ) * } ) => {
206
206
$( #[ $a] ) *
207
207
#[ derive( Clone , Debug , PartialEq ) ]
208
208
pub struct $id( pub $value) ;
@@ -225,6 +225,15 @@ macro_rules! header {
225
225
:: std:: fmt:: Display :: fmt( & * * self , f)
226
226
}
227
227
}
228
+ #[ allow( unused_imports) ]
229
+ mod $tm{
230
+ use std:: str ;
231
+ use $crate:: header:: * ;
232
+ use $crate:: mime:: * ;
233
+ use $crate:: method:: Method ;
234
+ use super :: $id as HeaderField ;
235
+ $( $tf) *
236
+ }
228
237
} ;
229
238
// List header, one or more items with "*" option
230
239
( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => { Any / ( $item: ty) +} $tm: ident{ $( $tf: item) * } ) => {
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ header! {
14
14
#[ doc="```" ]
15
15
// TODO: Use URL
16
16
( Referer , "Referer" ) => [ String ]
17
+
18
+ test_referer {
19
+ // Testcase from the RFC
20
+ test_header!( test1, vec![ b"http://www.example.org/hypertext/Overview.html" ] ) ;
21
+ }
17
22
}
18
23
19
24
bench_header ! ( bench, Referer , { vec![ b"http://foo.com/hello:3000" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ header! {
15
15
#[ doc="```" ]
16
16
// TODO: Maybe parse as defined in the spec?
17
17
( Server , "Server" ) => [ String ]
18
+
19
+ test_server {
20
+ // Testcase from RFC
21
+ test_header!( test1, vec![ b"CERN/3.0 libwww/2.17" ] ) ;
22
+ }
18
23
}
19
24
20
25
bench_header ! ( bench, Server , { vec![ b"Some String" . to_vec( ) ] } ) ;
Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ header! {
18
18
#[ doc="```" ]
19
19
// TODO: Maybe write parsing according to the spec? (Split the String)
20
20
( UserAgent , "User-Agent" ) => [ String ]
21
+
22
+ test_user_agent {
23
+ // Testcase from RFC
24
+ test_header!( test1, vec![ b"CERN-LineMode/2.15 libwww/2.17b3" ] ) ;
25
+ }
21
26
}
22
27
23
28
#[ test] fn test_format ( ) {
You can’t perform that action at this time.
0 commit comments