mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Move the HTTP connector in HttpState
This commit is contained in:
parent
12ddc891c6
commit
16863017a9
6 changed files with 13 additions and 22 deletions
|
@ -12,7 +12,6 @@ use openssl::ssl::{SslConnectorBuilder, SslMethod};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub struct HttpsConnector {
|
pub struct HttpsConnector {
|
||||||
ssl: OpensslClient,
|
ssl: OpensslClient,
|
||||||
|
@ -63,9 +62,9 @@ pub fn create_ssl_client(ca_file: &PathBuf) -> OpensslClient {
|
||||||
OpensslClient::from(ssl_connector)
|
OpensslClient::from(ssl_connector)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_http_connector(ssl_client: OpensslClient) -> Arc<Pool<Connector>> {
|
pub fn create_http_connector(ssl_client: OpensslClient) -> Pool<Connector> {
|
||||||
let https_connector = HttpsConnector::new(ssl_client);
|
let https_connector = HttpsConnector::new(ssl_client);
|
||||||
Arc::new(Pool::with_connector(Default::default(), https_connector))
|
Pool::with_connector(Default::default(), https_connector)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The basic logic here is to prefer ciphers with ECDSA certificates, Forward
|
// The basic logic here is to prefer ciphers with ECDSA certificates, Forward
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use blob_loader::load_blob_sync;
|
use blob_loader::load_blob_sync;
|
||||||
use connector::Connector;
|
|
||||||
use data_loader::decode;
|
use data_loader::decode;
|
||||||
use devtools_traits::DevtoolsControlMsg;
|
use devtools_traits::DevtoolsControlMsg;
|
||||||
use fetch::cors_cache::CorsCache;
|
use fetch::cors_cache::CorsCache;
|
||||||
|
@ -11,7 +10,6 @@ use filemanager_thread::FileManager;
|
||||||
use http_loader::{HttpState, determine_request_referrer, http_fetch};
|
use http_loader::{HttpState, determine_request_referrer, http_fetch};
|
||||||
use http_loader::{set_default_accept, set_default_accept_language};
|
use http_loader::{set_default_accept, set_default_accept_language};
|
||||||
use hyper::{Error, Result as HyperResult};
|
use hyper::{Error, Result as HyperResult};
|
||||||
use hyper::client::Pool;
|
|
||||||
use hyper::header::{Accept, AcceptLanguage, ContentLanguage, ContentType};
|
use hyper::header::{Accept, AcceptLanguage, ContentLanguage, ContentType};
|
||||||
use hyper::header::{Header, HeaderFormat, HeaderView, Headers, Referer as RefererHeader};
|
use hyper::header::{Header, HeaderFormat, HeaderView, Headers, Referer as RefererHeader};
|
||||||
use hyper::method::Method;
|
use hyper::method::Method;
|
||||||
|
@ -45,7 +43,6 @@ pub struct FetchContext {
|
||||||
pub user_agent: Cow<'static, str>,
|
pub user_agent: Cow<'static, str>,
|
||||||
pub devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
pub devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
||||||
pub filemanager: FileManager,
|
pub filemanager: FileManager,
|
||||||
pub connector: Arc<Pool<Connector>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type DoneChannel = Option<(Sender<Data>, Receiver<Data>)>;
|
pub type DoneChannel = Option<(Sender<Data>, Receiver<Data>)>;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use brotli::Decompressor;
|
use brotli::Decompressor;
|
||||||
use connector::Connector;
|
use connector::{Connector, create_http_connector};
|
||||||
use cookie;
|
use cookie;
|
||||||
use cookie_storage::CookieStorage;
|
use cookie_storage::CookieStorage;
|
||||||
use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg, HttpRequest as DevtoolsHttpRequest};
|
use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg, HttpRequest as DevtoolsHttpRequest};
|
||||||
|
@ -70,6 +70,7 @@ pub struct HttpState {
|
||||||
pub cookie_jar: RwLock<CookieStorage>,
|
pub cookie_jar: RwLock<CookieStorage>,
|
||||||
pub auth_cache: RwLock<AuthCache>,
|
pub auth_cache: RwLock<AuthCache>,
|
||||||
pub ssl_client: OpensslClient,
|
pub ssl_client: OpensslClient,
|
||||||
|
pub connector: Pool<Connector>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpState {
|
impl HttpState {
|
||||||
|
@ -78,7 +79,8 @@ impl 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,
|
ssl_client: ssl_client.clone(),
|
||||||
|
connector: create_http_connector(ssl_client),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1082,7 +1084,9 @@ fn http_network_fetch(request: &Request,
|
||||||
// do not. Once we support other kinds of fetches we'll need to be more fine grained here
|
// do not. Once we support other kinds of fetches we'll need to be more fine grained here
|
||||||
// since things like image fetches are classified differently by devtools
|
// since things like image fetches are classified differently by devtools
|
||||||
let is_xhr = request.destination == Destination::None;
|
let is_xhr = request.destination == Destination::None;
|
||||||
let wrapped_response = obtain_response(&context.connector, &url, &request.method,
|
let wrapped_response = obtain_response(&context.state.connector,
|
||||||
|
&url,
|
||||||
|
&request.method,
|
||||||
&request.headers,
|
&request.headers,
|
||||||
&request.body, &request.method,
|
&request.body, &request.method,
|
||||||
&request.pipeline_id, request.redirect_count + 1,
|
&request.pipeline_id, request.redirect_count + 1,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
//! A thread that takes a URL and streams back the binary data.
|
//! A thread that takes a URL and streams back the binary data.
|
||||||
use connector::{Connector, create_http_connector, create_ssl_client};
|
use connector::{create_http_connector, create_ssl_client};
|
||||||
use cookie;
|
use cookie;
|
||||||
use cookie_rs;
|
use cookie_rs;
|
||||||
use cookie_storage::CookieStorage;
|
use cookie_storage::CookieStorage;
|
||||||
|
@ -12,7 +12,6 @@ use fetch::methods::{FetchContext, fetch};
|
||||||
use filemanager_thread::{FileManager, TFDProvider};
|
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_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};
|
||||||
|
@ -45,7 +44,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>,
|
||||||
connector: Arc<Pool<Connector>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a tuple of (public, private) senders to the new threads.
|
/// Returns a tuple of (public, private) senders to the new threads.
|
||||||
|
@ -117,16 +115,15 @@ fn create_resource_groups(config_dir: Option<&Path>)
|
||||||
auth_cache: RwLock::new(auth_cache),
|
auth_cache: RwLock::new(auth_cache),
|
||||||
hsts_list: RwLock::new(hsts_list),
|
hsts_list: RwLock::new(hsts_list),
|
||||||
ssl_client: ssl_client.clone(),
|
ssl_client: ssl_client.clone(),
|
||||||
|
connector: create_http_connector(ssl_client),
|
||||||
};
|
};
|
||||||
let resource_group = ResourceGroup {
|
let resource_group = ResourceGroup {
|
||||||
http_state: Arc::new(http_state),
|
http_state: Arc::new(http_state),
|
||||||
connector: create_http_connector(ssl_client),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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(private_ssl_client.clone())),
|
http_state: Arc::new(HttpState::new(private_ssl_client)),
|
||||||
connector: create_http_connector(private_ssl_client),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
(resource_group, private_resource_group)
|
(resource_group, private_resource_group)
|
||||||
|
@ -339,7 +336,6 @@ impl CoreResourceManager {
|
||||||
let ua = self.user_agent.clone();
|
let ua = self.user_agent.clone();
|
||||||
let dc = self.devtools_chan.clone();
|
let dc = self.devtools_chan.clone();
|
||||||
let filemanager = self.filemanager.clone();
|
let filemanager = self.filemanager.clone();
|
||||||
let connector = group.connector.clone();
|
|
||||||
|
|
||||||
thread::Builder::new().name(format!("fetch thread for {}", init.url)).spawn(move || {
|
thread::Builder::new().name(format!("fetch thread for {}", init.url)).spawn(move || {
|
||||||
let mut request = Request::from_init(init);
|
let mut request = Request::from_init(init);
|
||||||
|
@ -352,7 +348,6 @@ impl CoreResourceManager {
|
||||||
user_agent: ua,
|
user_agent: ua,
|
||||||
devtools_chan: dc,
|
devtools_chan: dc,
|
||||||
filemanager: filemanager,
|
filemanager: filemanager,
|
||||||
connector: connector,
|
|
||||||
};
|
};
|
||||||
fetch(&mut request, &mut sender, &context);
|
fetch(&mut request, &mut sender, &context);
|
||||||
}).expect("Thread spawning failed");
|
}).expect("Thread spawning failed");
|
||||||
|
|
|
@ -23,7 +23,7 @@ use hyper::status::StatusCode;
|
||||||
use hyper::uri::RequestUri;
|
use hyper::uri::RequestUri;
|
||||||
use hyper_openssl;
|
use hyper_openssl;
|
||||||
use msg::constellation_msg::TEST_PIPELINE_ID;
|
use msg::constellation_msg::TEST_PIPELINE_ID;
|
||||||
use net::connector::{create_http_connector, create_ssl_client};
|
use net::connector::create_ssl_client;
|
||||||
use net::fetch::cors_cache::CorsCache;
|
use net::fetch::cors_cache::CorsCache;
|
||||||
use net::fetch::methods::FetchContext;
|
use net::fetch::methods::FetchContext;
|
||||||
use net::filemanager_thread::FileManager;
|
use net::filemanager_thread::FileManager;
|
||||||
|
@ -532,14 +532,12 @@ 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.clone());
|
|
||||||
|
|
||||||
let context = FetchContext {
|
let context = FetchContext {
|
||||||
state: Arc::new(HttpState::new(ssl_client)),
|
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(),
|
||||||
connector: connector,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,13 +56,11 @@ 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.clone());
|
|
||||||
FetchContext {
|
FetchContext {
|
||||||
state: Arc::new(HttpState::new(ssl_client)),
|
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(),
|
||||||
connector: connector,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl FetchTaskTarget for FetchResponseCollector {
|
impl FetchTaskTarget for FetchResponseCollector {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue