Move the SSL client in HttpState

This commit is contained in:
Anthony Ramine 2017-04-06 18:11:20 +02:00
parent 21eafebd37
commit 949a0827e0
4 changed files with 19 additions and 17 deletions

View file

@ -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,
}
}
}

View file

@ -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)
}