зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #15686 - Use serde_json to persist cookies in the net crate (from nox:serde-cookies); r=Ms2ger
Source-Repo: https://github.com/servo/servo Source-Revision: deabf9618438627edb04a76ebd086b612012fc75 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : a3c194f90e0efcf25351505e039bfd163507ee1b
This commit is contained in:
Родитель
cc2cd3e3ae
Коммит
728d8ad262
|
@ -602,7 +602,7 @@ dependencies = [
|
||||||
"devtools_traits 0.0.1",
|
"devtools_traits 0.0.1",
|
||||||
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper_serde 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper_serde 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
|
@ -620,7 +620,7 @@ dependencies = [
|
||||||
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper_serde 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper_serde 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"serde 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1165,13 +1165,14 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper_serde"
|
name = "hyper_serde"
|
||||||
version = "0.5.0"
|
version = "0.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mime 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"mime 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1638,7 +1639,7 @@ dependencies = [
|
||||||
"devtools_traits 0.0.1",
|
"devtools_traits 0.0.1",
|
||||||
"flate2 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"flate2 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper_serde 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper_serde 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"immeta 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"immeta 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1652,6 +1653,9 @@ dependencies = [
|
||||||
"openssl-verify 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"openssl-verify 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"profile_traits 0.0.1",
|
"profile_traits 0.0.1",
|
||||||
"rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_derive 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde_json 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"servo_config 0.0.1",
|
"servo_config 0.0.1",
|
||||||
"servo_url 0.0.1",
|
"servo_url 0.0.1",
|
||||||
"threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"threadpool 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1685,7 +1689,7 @@ dependencies = [
|
||||||
"devtools_traits 0.0.1",
|
"devtools_traits 0.0.1",
|
||||||
"flate2 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"flate2 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper_serde 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper_serde 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"net 0.0.1",
|
"net 0.0.1",
|
||||||
|
@ -1706,7 +1710,7 @@ dependencies = [
|
||||||
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper_serde 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper_serde 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -2209,7 +2213,7 @@ dependencies = [
|
||||||
"html5ever 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"html5ever 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"html5ever-atoms 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"html5ever-atoms 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper_serde 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper_serde 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"js 0.1.4 (git+https://github.com/servo/rust-mozjs)",
|
"js 0.1.4 (git+https://github.com/servo/rust-mozjs)",
|
||||||
|
@ -2312,7 +2316,7 @@ dependencies = [
|
||||||
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hyper_serde 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hyper_serde 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ipc-channel 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
|
@ -3416,7 +3420,7 @@ dependencies = [
|
||||||
"checksum html5ever-atoms 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f9bd86e3b6a5a7933a272cc0a854f24e371f31576e585c0b41e8f857270c5134"
|
"checksum html5ever-atoms 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f9bd86e3b6a5a7933a272cc0a854f24e371f31576e585c0b41e8f857270c5134"
|
||||||
"checksum httparse 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a6e7a63e511f9edffbab707141fbb8707d1a3098615fb2adbd5769cdfcc9b17d"
|
"checksum httparse 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a6e7a63e511f9edffbab707141fbb8707d1a3098615fb2adbd5769cdfcc9b17d"
|
||||||
"checksum hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)" = "1b9bf64f730d6ee4b0528a5f0a316363da9d8104318731509d4ccc86248f82b3"
|
"checksum hyper 0.9.18 (registry+https://github.com/rust-lang/crates.io-index)" = "1b9bf64f730d6ee4b0528a5f0a316363da9d8104318731509d4ccc86248f82b3"
|
||||||
"checksum hyper_serde 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "19065fedb73b4d5c617482cedfb3cfb092fc379870a7e3aadd16fd491838129a"
|
"checksum hyper_serde 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d602a93073c250f49b2e2d931cc1755a5f447824154dc3c711716dee29bd7486"
|
||||||
"checksum idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11"
|
"checksum idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11"
|
||||||
"checksum image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "979bad0502082fd60053a490282e87d6c89650942e3a270e0d4c83569c7f5899"
|
"checksum image 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "979bad0502082fd60053a490282e87d6c89650942e3a270e0d4c83569c7f5899"
|
||||||
"checksum immeta 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e76ecb1d64979a91c7fc5b7c0495ef1467e3cbff759044f2b88878a5a845ef7"
|
"checksum immeta 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e76ecb1d64979a91c7fc5b7c0495ef1467e3cbff759044f2b88878a5a845ef7"
|
||||||
|
|
|
@ -30,6 +30,9 @@ openssl = "0.7.6"
|
||||||
openssl-verify = "0.1"
|
openssl-verify = "0.1"
|
||||||
profile_traits = {path = "../profile_traits"}
|
profile_traits = {path = "../profile_traits"}
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
|
serde = "0.9"
|
||||||
|
serde_derive = "0.9"
|
||||||
|
serde_json = "0.9"
|
||||||
servo_config = {path = "../config"}
|
servo_config = {path = "../config"}
|
||||||
servo_url = {path = "../url"}
|
servo_url = {path = "../url"}
|
||||||
threadpool = "1.0"
|
threadpool = "1.0"
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//! http://tools.ietf.org/html/rfc6265
|
//! http://tools.ietf.org/html/rfc6265
|
||||||
|
|
||||||
use cookie_rs;
|
use cookie_rs;
|
||||||
|
use hyper_serde::{self, Serde};
|
||||||
use net_traits::CookieSource;
|
use net_traits::CookieSource;
|
||||||
use net_traits::pub_domains::is_pub_domain;
|
use net_traits::pub_domains::is_pub_domain;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
|
@ -16,14 +17,20 @@ use time::{Tm, now, at, Duration};
|
||||||
/// A stored cookie that wraps the definition in cookie-rs. This is used to implement
|
/// 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,
|
/// various behaviours defined in the spec that rely on an associated request URL,
|
||||||
/// which cookie-rs and hyper's header parsing do not support.
|
/// which cookie-rs and hyper's header parsing do not support.
|
||||||
#[derive(Clone, Debug, RustcDecodable, RustcEncodable)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Cookie {
|
pub struct Cookie {
|
||||||
|
#[serde(deserialize_with = "hyper_serde::deserialize",
|
||||||
|
serialize_with = "hyper_serde::serialize")]
|
||||||
pub cookie: cookie_rs::Cookie,
|
pub cookie: cookie_rs::Cookie,
|
||||||
pub host_only: bool,
|
pub host_only: bool,
|
||||||
pub persistent: bool,
|
pub persistent: bool,
|
||||||
|
#[serde(deserialize_with = "hyper_serde::deserialize",
|
||||||
|
serialize_with = "hyper_serde::serialize")]
|
||||||
pub creation_time: Tm,
|
pub creation_time: Tm,
|
||||||
|
#[serde(deserialize_with = "hyper_serde::deserialize",
|
||||||
|
serialize_with = "hyper_serde::serialize")]
|
||||||
pub last_access: Tm,
|
pub last_access: Tm,
|
||||||
pub expiry_time: Option<Tm>,
|
pub expiry_time: Option<Serde<Tm>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cookie {
|
impl Cookie {
|
||||||
|
@ -85,7 +92,7 @@ impl Cookie {
|
||||||
persistent: persistent,
|
persistent: persistent,
|
||||||
creation_time: now(),
|
creation_time: now(),
|
||||||
last_access: now(),
|
last_access: now(),
|
||||||
expiry_time: expiry_time,
|
expiry_time: expiry_time.map(Serde),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ use time::Tm;
|
||||||
|
|
||||||
extern crate time;
|
extern crate time;
|
||||||
|
|
||||||
#[derive(Clone, Debug, RustcDecodable, RustcEncodable)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct CookieStorage {
|
pub struct CookieStorage {
|
||||||
version: u32,
|
version: u32,
|
||||||
cookies_map: HashMap<String, Vec<Cookie>>,
|
cookies_map: HashMap<String, Vec<Cookie>>,
|
||||||
|
@ -192,7 +192,7 @@ fn reg_host<'a>(url: &'a str) -> String {
|
||||||
|
|
||||||
fn is_cookie_expired(cookie: &Cookie) -> bool {
|
fn is_cookie_expired(cookie: &Cookie) -> bool {
|
||||||
match cookie.expiry_time {
|
match cookie.expiry_time {
|
||||||
Some(t) => t.to_timespec() <= time::get_time(),
|
Some(ref t) => t.to_timespec() <= time::get_time(),
|
||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use net_traits::IncludeSubdomains;
|
use net_traits::IncludeSubdomains;
|
||||||
use net_traits::pub_domains::reg_suffix;
|
use net_traits::pub_domains::reg_suffix;
|
||||||
use rustc_serialize::json::decode;
|
use serde_json;
|
||||||
use servo_config::resource_files::read_resource_file;
|
use servo_config::resource_files::read_resource_file;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||||
|
@ -12,7 +12,7 @@ use std::str::from_utf8;
|
||||||
use time;
|
use time;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(RustcDecodable, RustcEncodable, Clone)]
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
pub struct HstsEntry {
|
pub struct HstsEntry {
|
||||||
pub host: String,
|
pub host: String,
|
||||||
pub include_subdomains: bool,
|
pub include_subdomains: bool,
|
||||||
|
@ -53,7 +53,7 @@ impl HstsEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcDecodable, RustcEncodable, Clone)]
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
pub struct HstsList {
|
pub struct HstsList {
|
||||||
pub entries_map: HashMap<String, Vec<HstsEntry>>,
|
pub entries_map: HashMap<String, Vec<HstsEntry>>,
|
||||||
}
|
}
|
||||||
|
@ -65,14 +65,14 @@ impl HstsList {
|
||||||
|
|
||||||
/// Create an `HstsList` from the bytes of a JSON preload file.
|
/// Create an `HstsList` from the bytes of a JSON preload file.
|
||||||
pub fn from_preload(preload_content: &[u8]) -> Option<HstsList> {
|
pub fn from_preload(preload_content: &[u8]) -> Option<HstsList> {
|
||||||
#[derive(RustcDecodable)]
|
#[derive(Deserialize)]
|
||||||
struct HstsEntries {
|
struct HstsEntries {
|
||||||
entries: Vec<HstsEntry>,
|
entries: Vec<HstsEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
let hsts_entries: Option<HstsEntries> = from_utf8(&preload_content)
|
let hsts_entries: Option<HstsEntries> = from_utf8(&preload_content)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|c| decode(c).ok());
|
.and_then(|c| serde_json::from_str(c).ok());
|
||||||
|
|
||||||
hsts_entries.map_or(None, |hsts_entries| {
|
hsts_entries.map_or(None, |hsts_entries| {
|
||||||
let mut hsts_list: HstsList = HstsList::new();
|
let mut hsts_list: HstsList = HstsList::new();
|
||||||
|
|
|
@ -27,6 +27,10 @@ extern crate openssl;
|
||||||
extern crate openssl_verify;
|
extern crate openssl_verify;
|
||||||
extern crate profile_traits;
|
extern crate profile_traits;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
|
extern crate serde;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
extern crate serde_json;
|
||||||
extern crate servo_config;
|
extern crate servo_config;
|
||||||
extern crate servo_url;
|
extern crate servo_url;
|
||||||
extern crate threadpool;
|
extern crate threadpool;
|
||||||
|
|
|
@ -23,8 +23,8 @@ use net_traits::{ResourceThreads, WebSocketCommunicate, WebSocketConnectData};
|
||||||
use net_traits::request::{Request, RequestInit};
|
use net_traits::request::{Request, RequestInit};
|
||||||
use net_traits::storage_thread::StorageThreadMsg;
|
use net_traits::storage_thread::StorageThreadMsg;
|
||||||
use profile_traits::time::ProfilerChan;
|
use profile_traits::time::ProfilerChan;
|
||||||
use rustc_serialize::{Decodable, Encodable};
|
use serde::{Deserialize, Serialize};
|
||||||
use rustc_serialize::json;
|
use serde_json;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::borrow::{Cow, ToOwned};
|
use std::borrow::{Cow, ToOwned};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -211,7 +211,7 @@ impl ResourceChannelManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_json_from_file<T>(data: &mut T, config_dir: &Path, filename: &str)
|
pub fn read_json_from_file<T>(data: &mut T, config_dir: &Path, filename: &str)
|
||||||
where T: Decodable
|
where T: Deserialize
|
||||||
{
|
{
|
||||||
let path = config_dir.join(filename);
|
let path = config_dir.join(filename);
|
||||||
let display = path.display();
|
let display = path.display();
|
||||||
|
@ -233,17 +233,17 @@ pub fn read_json_from_file<T>(data: &mut T, config_dir: &Path, filename: &str)
|
||||||
Ok(_) => println!("successfully read from {}", display),
|
Ok(_) => println!("successfully read from {}", display),
|
||||||
}
|
}
|
||||||
|
|
||||||
match json::decode(&string_buffer) {
|
match serde_json::from_str(&string_buffer) {
|
||||||
Ok(decoded_buffer) => *data = decoded_buffer,
|
Ok(decoded_buffer) => *data = decoded_buffer,
|
||||||
Err(why) => warn!("Could not decode buffer{}", why),
|
Err(why) => warn!("Could not decode buffer{}", why),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_json_to_file<T>(data: &T, config_dir: &Path, filename: &str)
|
pub fn write_json_to_file<T>(data: &T, config_dir: &Path, filename: &str)
|
||||||
where T: Encodable
|
where T: Serialize
|
||||||
{
|
{
|
||||||
let json_encoded: String;
|
let json_encoded: String;
|
||||||
match json::encode(&data) {
|
match serde_json::to_string_pretty(&data) {
|
||||||
Ok(d) => json_encoded = d,
|
Ok(d) => json_encoded = d,
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
}
|
}
|
||||||
|
@ -266,7 +266,7 @@ pub fn write_json_to_file<T>(data: &T, config_dir: &Path, filename: &str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcDecodable, RustcEncodable, Clone)]
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
pub struct AuthCacheEntry {
|
pub struct AuthCacheEntry {
|
||||||
pub user_name: String,
|
pub user_name: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
|
@ -281,7 +281,7 @@ impl AuthCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcDecodable, RustcEncodable, Clone)]
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
pub struct AuthCache {
|
pub struct AuthCache {
|
||||||
pub version: u32,
|
pub version: u32,
|
||||||
pub entries: HashMap<String, AuthCacheEntry>,
|
pub entries: HashMap<String, AuthCacheEntry>,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче