1
- use header:: { Header , HeaderFormat , CookiePair , CookieJar } ;
1
+ use header:: { Header , HeaderFormat } ;
2
2
use std:: fmt:: { self , Display } ;
3
3
use std:: str:: from_utf8;
4
4
@@ -21,7 +21,6 @@ use std::str::from_utf8;
21
21
/// # extern crate cookie;
22
22
/// # fn main() {
23
23
/// use hyper::header::{Headers, Cookie};
24
- /// use cookie::Cookie as CookiePair;
25
24
///
26
25
/// let mut headers = Headers::new();
27
26
///
@@ -33,9 +32,9 @@ use std::str::from_utf8;
33
32
/// # }
34
33
/// ```
35
34
#[ derive( Clone , PartialEq , Debug ) ]
36
- pub struct Cookie ( pub Vec < CookiePair > ) ;
35
+ pub struct Cookie ( pub Vec < String > ) ;
37
36
38
- __hyper__deref ! ( Cookie => Vec <CookiePair >) ;
37
+ __hyper__deref ! ( Cookie => Vec <String >) ;
39
38
40
39
impl Header for Cookie {
41
40
fn header_name ( ) -> & ' static str {
@@ -47,11 +46,7 @@ impl Header for Cookie {
47
46
for cookies_raw in raw. iter ( ) {
48
47
let cookies_str = try!( from_utf8 ( & cookies_raw[ ..] ) ) ;
49
48
for cookie_str in cookies_str. split ( ';' ) {
50
- if let Ok ( cookie) = cookie_str. trim ( ) . parse ( ) {
51
- cookies. push ( cookie) ;
52
- } else {
53
- return Err ( :: Error :: Header ) ;
54
- }
49
+ cookies. push ( cookie_str. trim ( ) . to_owned ( ) )
55
50
}
56
51
}
57
52
@@ -70,64 +65,10 @@ impl HeaderFormat for Cookie {
70
65
if i != 0 {
71
66
try!( f. write_str ( "; " ) ) ;
72
67
}
73
- try!( Display :: fmt ( & cookie. pair ( ) , f) ) ;
68
+ try!( Display :: fmt ( & cookie, f) ) ;
74
69
}
75
70
Ok ( ( ) )
76
71
}
77
72
}
78
73
79
- impl Cookie {
80
- /// This method can be used to create CookieJar that can be used
81
- /// to manipulate cookies and create a corresponding `SetCookie` header afterwards.
82
- pub fn to_cookie_jar ( & self , key : & [ u8 ] ) -> CookieJar < ' static > {
83
- let mut jar = CookieJar :: new ( key) ;
84
- for cookie in self . iter ( ) {
85
- jar. add_original ( cookie. clone ( ) ) ;
86
- }
87
- jar
88
- }
89
-
90
- /// Extracts all cookies from `CookieJar` and creates Cookie header.
91
- /// Useful for clients.
92
- pub fn from_cookie_jar ( jar : & CookieJar ) -> Cookie {
93
- Cookie ( jar. iter ( ) . collect ( ) )
94
- }
95
- }
96
-
97
-
98
- #[ test]
99
- fn test_parse ( ) {
100
- let h = Header :: parse_header ( & [ b"foo=bar; baz=quux" . to_vec ( ) ] [ ..] ) ;
101
- let c1 = CookiePair :: new ( "foo" . to_owned ( ) , "bar" . to_owned ( ) ) ;
102
- let c2 = CookiePair :: new ( "baz" . to_owned ( ) , "quux" . to_owned ( ) ) ;
103
- assert_eq ! ( h. ok( ) , Some ( Cookie ( vec![ c1, c2] ) ) ) ;
104
- }
105
-
106
- #[ test]
107
- fn test_fmt ( ) {
108
- use header:: Headers ;
109
-
110
- let mut cookie_pair = CookiePair :: new ( "foo" . to_owned ( ) , "bar" . to_owned ( ) ) ;
111
- cookie_pair. httponly = true ;
112
- cookie_pair. path = Some ( "/p" . to_owned ( ) ) ;
113
- let cookie_header = Cookie ( vec ! [
114
- cookie_pair,
115
- CookiePair :: new( "baz" . to_owned( ) , "quux" . to_owned( ) ) ] ) ;
116
- let mut headers = Headers :: new ( ) ;
117
- headers. set ( cookie_header) ;
118
-
119
- assert_eq ! ( & headers. to_string( ) [ ..] , "Cookie: foo=bar; baz=quux\r \n " ) ;
120
- }
121
-
122
- #[ test]
123
- fn cookie_jar ( ) {
124
- let cookie_pair = CookiePair :: new ( "foo" . to_owned ( ) , "bar" . to_owned ( ) ) ;
125
- let cookie_header = Cookie ( vec ! [ cookie_pair] ) ;
126
- let jar = cookie_header. to_cookie_jar ( & [ ] ) ;
127
- let new_cookie_header = Cookie :: from_cookie_jar ( & jar) ;
128
-
129
- assert_eq ! ( cookie_header, new_cookie_header) ;
130
- }
131
-
132
-
133
74
bench_header ! ( bench, Cookie , { vec![ b"foo=bar; baz=quux" . to_vec( ) ] } ) ;
0 commit comments