aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/net/http_loader.rs63
1 files changed, 8 insertions, 55 deletions
diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs
index 88d37877f54..eb2036d6cd6 100644
--- a/components/net/http_loader.rs
+++ b/components/net/http_loader.rs
@@ -40,7 +40,6 @@ use resource_thread::AuthCache;
use servo_url::ServoUrl;
use std::collections::HashSet;
use std::error::Error;
-use std::fmt;
use std::io::{self, Read, Write};
use std::iter::FromIterator;
use std::mem::swap;
@@ -129,7 +128,7 @@ struct NetworkHttpRequestFactory {
impl NetworkHttpRequestFactory {
fn create(&self, url: ServoUrl, method: Method, headers: Headers)
- -> Result<HyperRequest<Fresh>, LoadError> {
+ -> Result<HyperRequest<Fresh>, NetworkError> {
let connection = HyperRequest::with_connector(method,
url.clone().into_url().unwrap(),
&*self.connector);
@@ -152,15 +151,14 @@ impl NetworkHttpRequestFactory {
}
let error_report = error_report.join("<br>\n");
- return Err(LoadError::new(url, LoadErrorType::Ssl { reason: error_report }));
+ return Err(NetworkError::SslValidation(url, error_report));
}
}
}
let mut request = match connection {
Ok(req) => req,
- Err(e) => return Err(
- LoadError::new(url, LoadErrorType::Connection { reason: e.description().to_owned() })),
+ Err(e) => return Err(NetworkError::Internal(e.description().to_owned())),
};
*request.headers_mut() = headers;
@@ -168,42 +166,6 @@ impl NetworkHttpRequestFactory {
}
}
-#[derive(Debug)]
-struct LoadError {
- pub url: ServoUrl,
- pub error: LoadErrorType,
-}
-
-impl LoadError {
- pub fn new(url: ServoUrl, error: LoadErrorType) -> LoadError {
- LoadError {
- url: url,
- error: error,
- }
- }
-}
-
-#[derive(Eq, PartialEq, Debug)]
-enum LoadErrorType {
- Connection { reason: String },
- Ssl { reason: String },
-}
-
-impl fmt::Display for LoadErrorType {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{}", self.description())
- }
-}
-
-impl Error for LoadErrorType {
- fn description(&self) -> &str {
- match *self {
- LoadErrorType::Connection { ref reason } => reason,
- LoadErrorType::Ssl { ref reason } => reason,
- }
- }
-}
-
fn set_default_accept_encoding(headers: &mut Headers) {
if headers.has::<AcceptEncoding>() {
return
@@ -444,7 +406,7 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
iters: u32,
request_id: Option<&str>,
is_xhr: bool)
- -> Result<(WrappedHttpResponse, Option<ChromeToDevtoolsControlMsg>), LoadError> {
+ -> Result<(WrappedHttpResponse, Option<ChromeToDevtoolsControlMsg>), NetworkError> {
let null_data = None;
let connection_url = replace_hosts(&url);
@@ -495,14 +457,12 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
let mut request_writer = match request.start() {
Ok(streaming) => streaming,
- Err(e) => return Err(LoadError::new(connection_url,
- LoadErrorType::Connection { reason: e.description().to_owned() })),
+ Err(e) => return Err(NetworkError::Internal(e.description().to_owned())),
};
if let Some(ref data) = *request_body {
if let Err(e) = request_writer.write_all(&data) {
- return Err(LoadError::new(connection_url,
- LoadErrorType::Connection { reason: e.description().to_owned() }))
+ return Err(NetworkError::Internal(e.description().to_owned()))
}
}
@@ -512,8 +472,7 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
debug!("connection aborted ({:?}), possibly stale, trying new connection", io_error.description());
continue;
},
- Err(e) => return Err(LoadError::new(connection_url,
- LoadErrorType::Connection { reason: e.description().to_owned() })),
+ Err(e) => return Err(NetworkError::Internal(e.description().to_owned())),
};
let send_end = precise_time_ms();
@@ -1089,13 +1048,7 @@ fn http_network_fetch(request: Rc<Request>,
let pipeline_id = request.pipeline_id.get();
let (res, msg) = match wrapped_response {
Ok(wrapped_response) => wrapped_response,
- Err(error) => {
- let error = match error.error {
- LoadErrorType::Ssl { reason } => NetworkError::SslValidation(error.url, reason),
- e => NetworkError::Internal(e.description().to_owned())
- };
- return Response::network_error(error);
- }
+ Err(error) => return Response::network_error(error),
};
let mut response = Response::new(url.clone());