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::method::Method;
|
||||
use hyper::status::StatusCode;
|
||||
use hyper_openssl::OpensslClient;
|
||||
use hyper_serde::Serde;
|
||||
use log;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
|
@ -68,14 +69,16 @@ pub struct HttpState {
|
|||
pub hsts_list: RwLock<HstsList>,
|
||||
pub cookie_jar: RwLock<CookieStorage>,
|
||||
pub auth_cache: RwLock<AuthCache>,
|
||||
pub ssl_client: OpensslClient,
|
||||
}
|
||||
|
||||
impl HttpState {
|
||||
pub fn new() -> HttpState {
|
||||
pub fn new(ssl_client: OpensslClient) -> HttpState {
|
||||
HttpState {
|
||||
hsts_list: RwLock::new(HstsList::new()),
|
||||
cookie_jar: RwLock::new(CookieStorage::new(150)),
|
||||
auth_cache: RwLock::new(AuthCache::new()),
|
||||
ssl_client: ssl_client,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ use filemanager_thread::{FileManager, TFDProvider};
|
|||
use hsts::HstsList;
|
||||
use http_loader::HttpState;
|
||||
use hyper::client::pool::Pool;
|
||||
use hyper_openssl::OpensslClient;
|
||||
use hyper_serde::Serde;
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcReceiverSet, IpcSender};
|
||||
use net_traits::{CookieSource, CoreResourceThread};
|
||||
|
@ -46,7 +45,6 @@ const TFD_PROVIDER: &'static TFDProvider = &TFDProvider;
|
|||
#[derive(Clone)]
|
||||
pub struct ResourceGroup {
|
||||
http_state: Arc<HttpState>,
|
||||
ssl_client: OpensslClient,
|
||||
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 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 {
|
||||
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")
|
||||
.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 {
|
||||
http_state: Arc::new(http_state),
|
||||
ssl_client: ssl_client.clone(),
|
||||
connector: create_http_connector(ssl_client.clone()),
|
||||
connector: create_http_connector(ssl_client),
|
||||
};
|
||||
|
||||
let private_ssl_client = create_ssl_client(&ca_file);
|
||||
let private_resource_group = ResourceGroup {
|
||||
http_state: Arc::new(HttpState::new()),
|
||||
ssl_client: private_ssl_client.clone(),
|
||||
http_state: Arc::new(HttpState::new(private_ssl_client.clone())),
|
||||
connector: create_http_connector(private_ssl_client),
|
||||
};
|
||||
|
||||
(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 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 {
|
||||
state: Arc::new(HttpState::new()),
|
||||
state: Arc::new(HttpState::new(ssl_client)),
|
||||
user_agent: DEFAULT_USER_AGENT.into(),
|
||||
devtools_chan: None,
|
||||
filemanager: FileManager::new(),
|
||||
|
|
|
@ -56,9 +56,9 @@ struct FetchResponseCollector {
|
|||
fn new_fetch_context(dc: Option<Sender<DevtoolsControlMsg>>) -> FetchContext {
|
||||
let ca_file = resources_dir_path().unwrap().join("certs");
|
||||
let ssl_client = create_ssl_client(&ca_file);
|
||||
let connector = create_http_connector(ssl_client);
|
||||
let connector = create_http_connector(ssl_client.clone());
|
||||
FetchContext {
|
||||
state: Arc::new(HttpState::new()),
|
||||
state: Arc::new(HttpState::new(ssl_client)),
|
||||
user_agent: DEFAULT_USER_AGENT.into(),
|
||||
devtools_chan: dc,
|
||||
filemanager: FileManager::new(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue