diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-25 18:10:40 -0700 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-04-25 18:10:40 -0700 |
commit | 7a582b4bf9bdaeff34c8c813a92f35226ced72f5 (patch) | |
tree | 2c201cb5d5431e8b40c47aa44a6f519d60496dc9 /components/net/cookie.rs | |
parent | 81f6e70a623a6f11535322ed2ef954eafaf8c70c (diff) | |
parent | d9c32b273af4f55064016b66ccc8d65ec031448c (diff) | |
download | servo-7a582b4bf9bdaeff34c8c813a92f35226ced72f5.tar.gz servo-7a582b4bf9bdaeff34c8c813a92f35226ced72f5.zip |
Auto merge of #10800 - DDEFISHER:read_profile_dir_from_file, r=frewsxcv
read cookie_jar, hsts_list, auth_cache, and local_data from file if profile_dir option is present
Last step in Persistent sessions student project
"check for the presence of the profile directory command-line option in the ResourceThread constructor and look for files that will contain serialized versions of the previous steps. If they exist, populate the appropriate fields with deserialized versions of the file contents."
Also populated local_data in StorageManager constructor
I am not sure if the handling of decoding and encoding the Option Tm type was done in the cleanest way here.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10800)
<!-- Reviewable:end -->
Diffstat (limited to 'components/net/cookie.rs')
-rw-r--r-- | components/net/cookie.rs | 65 |
1 files changed, 1 insertions, 64 deletions
diff --git a/components/net/cookie.rs b/components/net/cookie.rs index 0d82c196cca..e85f0b41397 100644 --- a/components/net/cookie.rs +++ b/components/net/cookie.rs @@ -8,7 +8,6 @@ use cookie_rs; use net_traits::CookieSource; use pub_domains::PUB_DOMAINS; -use rustc_serialize::{Encodable, Encoder}; use std::borrow::ToOwned; use std::net::{Ipv4Addr, Ipv6Addr}; use time::{Tm, now, at, Duration}; @@ -17,7 +16,7 @@ use url::Url; /// A stored cookie that wraps the definition in cookie-rs. This is used to implement /// various behaviours defined in the spec that rely on an associated request URL, /// which cookie-rs and hyper's header parsing do not support. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, RustcDecodable, RustcEncodable)] pub struct Cookie { pub cookie: cookie_rs::Cookie, pub host_only: bool, @@ -174,65 +173,3 @@ impl Cookie { true } } - -impl Encodable for Cookie { - fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - s.emit_struct("Cookie", 6, |e| { - try!(e.emit_struct_field("cookie", 0, |e| RsCookie(self.cookie.clone()).encode(e))); - try!(e.emit_struct_field("host_only", 1, |e| self.host_only.encode(e))); - try!(e.emit_struct_field("persistent", 2, |e| self.persistent.encode(e))); - try!(e.emit_struct_field("creation_time", 3, |e| Time(self.creation_time).encode(e))); - try!(e.emit_struct_field("last_access", 4, |e| Time(self.last_access).encode(e))); - match self.expiry_time { - Some(time) => try!(e.emit_struct_field("expiry_time", 5, |e| Time(time).encode(e))), - None => {}, - } - Ok(()) - }) - } -} - -struct Time(Tm); - -impl Encodable for Time { - fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - let Time(time) = *self; - s.emit_struct("Time", 11, |e| { - try!(e.emit_struct_field("tm_sec", 0, |e| time.tm_sec.encode(e))); - try!(e.emit_struct_field("tm_min", 1, |e| time.tm_min.encode(e))); - try!(e.emit_struct_field("tm_hour", 2, |e| time.tm_hour.encode(e))); - try!(e.emit_struct_field("tm_mday", 3, |e| time.tm_mday.encode(e))); - try!(e.emit_struct_field("tm_mon", 4, |e| time.tm_mon.encode(e))); - try!(e.emit_struct_field("tm_year", 5, |e| time.tm_year.encode(e))); - try!(e.emit_struct_field("tm_wday", 6, |e| time.tm_wday.encode(e))); - try!(e.emit_struct_field("tm_yday", 7, |e| time.tm_yday.encode(e))); - try!(e.emit_struct_field("tm_isdst", 8, |e| time.tm_isdst.encode(e))); - try!(e.emit_struct_field("tm_utcoff", 9, |e| time.tm_utcoff.encode(e))); - try!(e.emit_struct_field("tm_nsec", 10, |e| time.tm_nsec.encode(e))); - Ok(()) - }) - } -} - -struct RsCookie(cookie_rs::Cookie); - -impl Encodable for RsCookie { - fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> { - let RsCookie(ref rs_cookie) = *self; - s.emit_struct("RsCookie", 9, |e| { - try!(e.emit_struct_field("name", 0, |e| rs_cookie.name.encode(e))); - try!(e.emit_struct_field("value", 1, |e| rs_cookie.value.encode(e))); - match rs_cookie.expires { - Some(time) => try!(e.emit_struct_field("expires", 2, |e| Time(time).encode(e))), - None => {}, - } - try!(e.emit_struct_field("max_age", 3, |e| rs_cookie.max_age.encode(e))); - try!(e.emit_struct_field("domain", 4, |e| rs_cookie.domain.encode(e))); - try!(e.emit_struct_field("path", 5, |e| rs_cookie.path.encode(e))); - try!(e.emit_struct_field("secure", 6, |e| rs_cookie.secure.encode(e))); - try!(e.emit_struct_field("httponly", 7, |e| rs_cookie.httponly.encode(e))); - try!(e.emit_struct_field("custom", 8, |e| rs_cookie.custom.encode(e))); - Ok(()) - }) - } -} |