feat(headers): re-export CookiePair and CookieJar

This commit is contained in:
Sean McArthur
2015-11-20 13:15:07 -08:00
parent 81d42c964e
commit 799698ca87
3 changed files with 11 additions and 14 deletions

View File

@@ -1,10 +1,7 @@
use header::{Header, HeaderFormat}; use header::{Header, HeaderFormat, CookiePair, CookieJar};
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use std::str::from_utf8; use std::str::from_utf8;
use cookie::Cookie as CookiePair;
use cookie::CookieJar;
/// `Cookie` header, defined in [RFC6265](http://tools.ietf.org/html/rfc6265#section-5.4) /// `Cookie` header, defined in [RFC6265](http://tools.ietf.org/html/rfc6265#section-5.4)
/// ///
/// If the user agent does attach a Cookie header field to an HTTP /// If the user agent does attach a Cookie header field to an HTTP

View File

@@ -1,9 +1,7 @@
use header::{Header, HeaderFormat}; use header::{Header, HeaderFormat, CookiePair, CookieJar};
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use std::str::from_utf8; use std::str::from_utf8;
use cookie::Cookie;
use cookie::CookieJar;
/// `Set-Cookie` header, defined [RFC6265](http://tools.ietf.org/html/rfc6265#section-4.1) /// `Set-Cookie` header, defined [RFC6265](http://tools.ietf.org/html/rfc6265#section-4.1)
/// ///
@@ -80,9 +78,9 @@ use cookie::CookieJar;
/// # } /// # }
/// ``` /// ```
#[derive(Clone, PartialEq, Debug)] #[derive(Clone, PartialEq, Debug)]
pub struct SetCookie(pub Vec<Cookie>); pub struct SetCookie(pub Vec<CookiePair>);
__hyper__deref!(SetCookie => Vec<Cookie>); __hyper__deref!(SetCookie => Vec<CookiePair>);
impl Header for SetCookie { impl Header for SetCookie {
fn header_name() -> &'static str { fn header_name() -> &'static str {
@@ -142,7 +140,7 @@ impl SetCookie {
#[test] #[test]
fn test_parse() { fn test_parse() {
let h = Header::parse_header(&[b"foo=bar; HttpOnly".to_vec()][..]); let h = Header::parse_header(&[b"foo=bar; HttpOnly".to_vec()][..]);
let mut c1 = Cookie::new("foo".to_owned(), "bar".to_owned()); let mut c1 = CookiePair::new("foo".to_owned(), "bar".to_owned());
c1.httponly = true; c1.httponly = true;
assert_eq!(h.ok(), Some(SetCookie(vec![c1]))); assert_eq!(h.ok(), Some(SetCookie(vec![c1])));
@@ -152,10 +150,10 @@ fn test_parse() {
fn test_fmt() { fn test_fmt() {
use header::Headers; use header::Headers;
let mut cookie = Cookie::new("foo".to_owned(), "bar".to_owned()); let mut cookie = CookiePair::new("foo".to_owned(), "bar".to_owned());
cookie.httponly = true; cookie.httponly = true;
cookie.path = Some("/p".to_owned()); cookie.path = Some("/p".to_owned());
let cookies = SetCookie(vec![cookie, Cookie::new("baz".to_owned(), "quux".to_owned())]); let cookies = SetCookie(vec![cookie, CookiePair::new("baz".to_owned(), "quux".to_owned())]);
let mut headers = Headers::new(); let mut headers = Headers::new();
headers.set(cookies); headers.set(cookies);
@@ -167,7 +165,7 @@ fn test_fmt() {
#[test] #[test]
fn cookie_jar() { fn cookie_jar() {
let jar = CookieJar::new(b"secret"); let jar = CookieJar::new(b"secret");
let cookie = Cookie::new("foo".to_owned(), "bar".to_owned()); let cookie = CookiePair::new("foo".to_owned(), "bar".to_owned());
jar.add(cookie); jar.add(cookie);
let cookies = SetCookie::from_cookie_jar(&jar); let cookies = SetCookie::from_cookie_jar(&jar);
@@ -176,5 +174,5 @@ fn cookie_jar() {
cookies.apply_to_cookie_jar(&mut new_jar); cookies.apply_to_cookie_jar(&mut new_jar);
assert_eq!(jar.find("foo"), new_jar.find("foo")); assert_eq!(jar.find("foo"), new_jar.find("foo"));
assert_eq!(jar.iter().collect::<Vec<Cookie>>(), new_jar.iter().collect::<Vec<Cookie>>()); assert_eq!(jar.iter().collect::<Vec<CookiePair>>(), new_jar.iter().collect::<Vec<CookiePair>>());
} }

View File

@@ -1,4 +1,6 @@
pub use self::charset::Charset; pub use self::charset::Charset;
pub use cookie::Cookie as CookiePair;
pub use cookie::CookieJar;
pub use self::encoding::Encoding; pub use self::encoding::Encoding;
pub use self::entity::EntityTag; pub use self::entity::EntityTag;
pub use self::httpdate::HttpDate; pub use self::httpdate::HttpDate;