mirror of
https://github.com/servo/servo.git
synced 2025-07-30 02:30:21 +01:00
Injects the network connector as a dependency into http_loader::load
servo/servo#6727
This commit is contained in:
parent
610ef40105
commit
c8c36f4490
1 changed files with 23 additions and 14 deletions
|
@ -21,7 +21,7 @@ use hyper::header::StrictTransportSecurity;
|
||||||
use hyper::header::{AcceptEncoding, Accept, ContentLength, ContentType, Host, Location, qitem, Quality, QualityItem};
|
use hyper::header::{AcceptEncoding, Accept, ContentLength, ContentType, Host, Location, qitem, Quality, QualityItem};
|
||||||
use hyper::method::Method;
|
use hyper::method::Method;
|
||||||
use hyper::mime::{Mime, TopLevel, SubLevel};
|
use hyper::mime::{Mime, TopLevel, SubLevel};
|
||||||
use hyper::net::{HttpConnector, HttpsConnector, Openssl};
|
use hyper::net::{HttpStream, HttpConnector, HttpsConnector, Openssl, NetworkConnector, NetworkStream};
|
||||||
use hyper::status::{StatusCode, StatusClass};
|
use hyper::status::{StatusCode, StatusClass};
|
||||||
use ipc_channel::ipc::{self, IpcSender};
|
use ipc_channel::ipc::{self, IpcSender};
|
||||||
use log;
|
use log;
|
||||||
|
@ -100,7 +100,21 @@ fn load_for_consumer(load_data: LoadData,
|
||||||
resource_mgr_chan: IpcSender<ControlMsg>,
|
resource_mgr_chan: IpcSender<ControlMsg>,
|
||||||
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
||||||
hsts_list: Arc<Mutex<HSTSList>>) {
|
hsts_list: Arc<Mutex<HSTSList>>) {
|
||||||
match load(load_data, resource_mgr_chan, devtools_chan, hsts_list) {
|
|
||||||
|
let connector = {
|
||||||
|
// TODO: Is this still necessary? The type system is making it really hard to support both
|
||||||
|
// connectors. SSL is working, so it's not clear to me if the original rationale still
|
||||||
|
// stands
|
||||||
|
// if opts::get().nossl {
|
||||||
|
// &HttpConnector
|
||||||
|
let mut context = SslContext::new(SslMethod::Sslv23).unwrap();
|
||||||
|
context.set_verify(SSL_VERIFY_PEER, None);
|
||||||
|
context.set_CA_file(&resources_dir_path().join("certs")).unwrap();
|
||||||
|
|
||||||
|
&HttpsConnector::new(Openssl { context: Arc::new(context) })
|
||||||
|
};
|
||||||
|
|
||||||
|
match load(load_data, resource_mgr_chan, devtools_chan, hsts_list, connector) {
|
||||||
Err(LoadError::UnsupportedScheme(url)) => {
|
Err(LoadError::UnsupportedScheme(url)) => {
|
||||||
let s = format!("{} request, but we don't support that scheme", &*url.scheme);
|
let s = format!("{} request, but we don't support that scheme", &*url.scheme);
|
||||||
send_error(url, s, start_chan)
|
send_error(url, s, start_chan)
|
||||||
|
@ -133,10 +147,14 @@ enum LoadError {
|
||||||
MaxRedirects(Url)
|
MaxRedirects(Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load(mut load_data: LoadData,
|
fn load<C, S>(mut load_data: LoadData,
|
||||||
resource_mgr_chan: IpcSender<ControlMsg>,
|
resource_mgr_chan: IpcSender<ControlMsg>,
|
||||||
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
devtools_chan: Option<Sender<DevtoolsControlMsg>>,
|
||||||
hsts_list: Arc<Mutex<HSTSList>>) -> Result<(Box<Read>, Metadata), LoadError> {
|
hsts_list: Arc<Mutex<HSTSList>>,
|
||||||
|
connector: &C) -> Result<(Box<Read>, Metadata), LoadError> where
|
||||||
|
C: NetworkConnector<Stream=S>,
|
||||||
|
S: Into<Box<NetworkStream + Send>> {
|
||||||
|
|
||||||
// FIXME: At the time of writing this FIXME, servo didn't have any central
|
// FIXME: At the time of writing this FIXME, servo didn't have any central
|
||||||
// location for configuration. If you're reading this and such a
|
// location for configuration. If you're reading this and such a
|
||||||
// repository DOES exist, please update this constant to use it.
|
// repository DOES exist, please update this constant to use it.
|
||||||
|
@ -183,20 +201,11 @@ fn load(mut load_data: LoadData,
|
||||||
|
|
||||||
info!("requesting {}", url.serialize());
|
info!("requesting {}", url.serialize());
|
||||||
|
|
||||||
// TODO - Is no ssl still needed?
|
|
||||||
let ssl_err_string = "Some(OpenSslErrors([UnknownError { library: \"SSL routines\", \
|
let ssl_err_string = "Some(OpenSslErrors([UnknownError { library: \"SSL routines\", \
|
||||||
function: \"SSL3_GET_SERVER_CERTIFICATE\", \
|
function: \"SSL3_GET_SERVER_CERTIFICATE\", \
|
||||||
reason: \"certificate verify failed\" }]))";
|
reason: \"certificate verify failed\" }]))";
|
||||||
|
|
||||||
let req = if opts::get().nossl {
|
let req = Request::with_connector(load_data.method.clone(), url.clone(), connector);
|
||||||
Request::with_connector(load_data.method.clone(), url.clone(), &HttpConnector)
|
|
||||||
} else {
|
|
||||||
let mut context = SslContext::new(SslMethod::Sslv23).unwrap();
|
|
||||||
context.set_verify(SSL_VERIFY_PEER, None);
|
|
||||||
context.set_CA_file(&resources_dir_path().join("certs")).unwrap();
|
|
||||||
Request::with_connector(load_data.method.clone(), url.clone(),
|
|
||||||
&HttpsConnector::new(Openssl { context: Arc::new(context) }))
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut req = match req {
|
let mut req = match req {
|
||||||
Ok(req) => req,
|
Ok(req) => req,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue