mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Move the SSL client in HttpState
This commit is contained in:
parent
21eafebd37
commit
949a0827e0
4 changed files with 19 additions and 17 deletions
|
@ -27,6 +27,7 @@ use hyper::header::{Pragma, Quality, QualityItem, Referer, SetCookie};
|
||||||
use hyper::header::{UserAgent, q, qitem};
|
use hyper::header::{UserAgent, q, qitem};
|
||||||
use hyper::method::Method;
|
use hyper::method::Method;
|
||||||
use hyper::status::StatusCode;
|
use hyper::status::StatusCode;
|
||||||
|
use hyper_openssl::OpensslClient;
|
||||||
use hyper_serde::Serde;
|
use hyper_serde::Serde;
|
||||||
use log;
|
use log;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
|
@ -68,14 +69,16 @@ pub struct HttpState {
|
||||||
pub hsts_list: RwLock<HstsList>,
|
pub hsts_list: RwLock<HstsList>,
|
||||||
pub cookie_jar: RwLock<CookieStorage>,
|
pub cookie_jar: RwLock<CookieStorage>,
|
||||||
pub auth_cache: RwLock<AuthCache>,
|
pub auth_cache: RwLock<AuthCache>,
|
||||||
|
pub ssl_client: OpensslClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpState {
|
impl HttpState {
|
||||||
pub fn new() -> HttpState {
|
pub fn new(ssl_client: OpensslClient) -> HttpState {
|
||||||
HttpState {
|
HttpState {
|
||||||
hsts_list: RwLock::new(HstsList::new()),
|
hsts_list: RwLock::new(HstsList::new()),
|
||||||
cookie_jar: RwLock::new(CookieStorage::new(150)),
|
cookie_jar: RwLock::new(CookieStorage::new(150)),
|
||||||
auth_cache: RwLock::new(AuthCache::new()),
|
auth_cache: RwLock::new(AuthCache::new()),
|
||||||
|
ssl_client: ssl_client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ use filemanager_thread::{FileManager, TFDProvider};
|
||||||
use hsts::HstsList;
|
use hsts::HstsList;
|
||||||
use http_loader::HttpState;
|
use http_loader::HttpState;
|
||||||
use hyper::client::pool::Pool;
|
use hyper::client::pool::Pool;
|
||||||
use hyper_openssl::OpensslClient;
|
|
||||||
use hyper_serde::Serde;
|
use hyper_serde::Serde;
|
||||||
use ipc_channel::ipc::{self, IpcReceiver, IpcReceiverSet, IpcSender};
|
use ipc_channel::ipc::{self, IpcReceiver, IpcReceiverSet, IpcSender};
|
||||||
use net_traits::{CookieSource, CoreResourceThread};
|
use net_traits::{CookieSource, CoreResourceThread};
|
||||||
|
@ -46,7 +45,6 @@ const TFD_PROVIDER: &'static TFDProvider = &TFDProvider;
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ResourceGroup {
|
pub struct ResourceGroup {
|
||||||
http_state: Arc<HttpState>,
|
http_state: Arc<HttpState>,
|
||||||
ssl_client: OpensslClient,
|
|
||||||
connector: Arc<Pool<Connector>>,
|
connector: Arc<Pool<Connector>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,11 +103,6 @@ fn create_resource_groups(config_dir: Option<&Path>)
|
||||||
read_json_from_file(&mut hsts_list, config_dir, "hsts_list.json");
|
read_json_from_file(&mut hsts_list, config_dir, "hsts_list.json");
|
||||||
read_json_from_file(&mut cookie_jar, config_dir, "cookie_jar.json");
|
read_json_from_file(&mut cookie_jar, config_dir, "cookie_jar.json");
|
||||||
}
|
}
|
||||||
let http_state = HttpState {
|
|
||||||
cookie_jar: RwLock::new(cookie_jar),
|
|
||||||
auth_cache: RwLock::new(auth_cache),
|
|
||||||
hsts_list: RwLock::new(hsts_list),
|
|
||||||
};
|
|
||||||
|
|
||||||
let ca_file = match opts::get().certificate_path {
|
let ca_file = match opts::get().certificate_path {
|
||||||
Some(ref path) => PathBuf::from(path),
|
Some(ref path) => PathBuf::from(path),
|
||||||
|
@ -117,19 +110,25 @@ fn create_resource_groups(config_dir: Option<&Path>)
|
||||||
.expect("Need certificate file to make network requests")
|
.expect("Need certificate file to make network requests")
|
||||||
.join("certs"),
|
.join("certs"),
|
||||||
};
|
};
|
||||||
let ssl_client = create_ssl_client(&ca_file);
|
|
||||||
|
|
||||||
|
let ssl_client = create_ssl_client(&ca_file);
|
||||||
|
let http_state = HttpState {
|
||||||
|
cookie_jar: RwLock::new(cookie_jar),
|
||||||
|
auth_cache: RwLock::new(auth_cache),
|
||||||
|
hsts_list: RwLock::new(hsts_list),
|
||||||
|
ssl_client: ssl_client.clone(),
|
||||||
|
};
|
||||||
let resource_group = ResourceGroup {
|
let resource_group = ResourceGroup {
|
||||||
http_state: Arc::new(http_state),
|
http_state: Arc::new(http_state),
|
||||||
ssl_client: ssl_client.clone(),
|
connector: create_http_connector(ssl_client),
|
||||||
connector: create_http_connector(ssl_client.clone()),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let private_ssl_client = create_ssl_client(&ca_file);
|
let private_ssl_client = create_ssl_client(&ca_file);
|
||||||
let private_resource_group = ResourceGroup {
|
let private_resource_group = ResourceGroup {
|
||||||
http_state: Arc::new(HttpState::new()),
|
http_state: Arc::new(HttpState::new(private_ssl_client.clone())),
|
||||||
ssl_client: private_ssl_client.clone(),
|
|
||||||
connector: create_http_connector(private_ssl_client),
|
connector: create_http_connector(private_ssl_client),
|
||||||
};
|
};
|
||||||
|
|
||||||
(resource_group, private_resource_group)
|
(resource_group, private_resource_group)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -532,10 +532,10 @@ fn test_fetch_with_hsts() {
|
||||||
|
|
||||||
let ca_file = resources_dir_path().unwrap().join("self_signed_certificate_for_testing.crt");
|
let ca_file = resources_dir_path().unwrap().join("self_signed_certificate_for_testing.crt");
|
||||||
let ssl_client = create_ssl_client(&ca_file);
|
let ssl_client = create_ssl_client(&ca_file);
|
||||||
let connector = create_http_connector(ssl_client);
|
let connector = create_http_connector(ssl_client.clone());
|
||||||
|
|
||||||
let context = FetchContext {
|
let context = FetchContext {
|
||||||
state: Arc::new(HttpState::new()),
|
state: Arc::new(HttpState::new(ssl_client)),
|
||||||
user_agent: DEFAULT_USER_AGENT.into(),
|
user_agent: DEFAULT_USER_AGENT.into(),
|
||||||
devtools_chan: None,
|
devtools_chan: None,
|
||||||
filemanager: FileManager::new(),
|
filemanager: FileManager::new(),
|
||||||
|
|
|
@ -56,9 +56,9 @@ struct FetchResponseCollector {
|
||||||
fn new_fetch_context(dc: Option<Sender<DevtoolsControlMsg>>) -> FetchContext {
|
fn new_fetch_context(dc: Option<Sender<DevtoolsControlMsg>>) -> FetchContext {
|
||||||
let ca_file = resources_dir_path().unwrap().join("certs");
|
let ca_file = resources_dir_path().unwrap().join("certs");
|
||||||
let ssl_client = create_ssl_client(&ca_file);
|
let ssl_client = create_ssl_client(&ca_file);
|
||||||
let connector = create_http_connector(ssl_client);
|
let connector = create_http_connector(ssl_client.clone());
|
||||||
FetchContext {
|
FetchContext {
|
||||||
state: Arc::new(HttpState::new()),
|
state: Arc::new(HttpState::new(ssl_client)),
|
||||||
user_agent: DEFAULT_USER_AGENT.into(),
|
user_agent: DEFAULT_USER_AGENT.into(),
|
||||||
devtools_chan: dc,
|
devtools_chan: dc,
|
||||||
filemanager: FileManager::new(),
|
filemanager: FileManager::new(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue