aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMs2ger <Ms2ger@gmail.com>2016-11-22 11:41:50 +0100
committerMs2ger <Ms2ger@gmail.com>2016-11-24 14:00:44 +0100
commit04d5f6e7fafe04108e91114ddfd4a48972dc8cbb (patch)
treea16388c741b645b2bc65a87d23b11363f3a2d2b7
parent53856bf3122050684886a95687285666aafd2cc1 (diff)
downloadservo-04d5f6e7fafe04108e91114ddfd4a48972dc8cbb.tar.gz
servo-04d5f6e7fafe04108e91114ddfd4a48972dc8cbb.zip
Inline WrappedHttpRequest::send().
-rw-r--r--components/net/http_loader.rs64
1 files changed, 21 insertions, 43 deletions
diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs
index 29fbcffdda5..68237dc16a9 100644
--- a/components/net/http_loader.rs
+++ b/components/net/http_loader.rs
@@ -172,33 +172,6 @@ pub struct WrappedHttpRequest {
request: HyperRequest<Fresh>
}
-impl WrappedHttpRequest {
- fn send(self, body: &Option<Vec<u8>>) -> Result<WrappedHttpResponse, LoadError> {
- let url = ServoUrl::from_url(self.request.url.clone());
- let mut request_writer = match self.request.start() {
- Ok(streaming) => streaming,
- Err(e) => return Err(LoadError::new(url, LoadErrorType::Connection { reason: e.description().to_owned() })),
- };
-
- if let Some(ref data) = *body {
- if let Err(e) = request_writer.write_all(&data) {
- return Err(LoadError::new(url, LoadErrorType::Connection { reason: e.description().to_owned() }))
- }
- }
-
- let response = match request_writer.send() {
- Ok(w) => w,
- Err(HttpError::Io(ref io_error)) if io_error.kind() == io::ErrorKind::ConnectionAborted => {
- let error_type = LoadErrorType::ConnectionAborted { reason: io_error.description().to_owned() };
- return Err(LoadError::new(url, error_type));
- },
- Err(e) => return Err(LoadError::new(url, LoadErrorType::Connection { reason: e.description().to_owned() })),
- };
-
- Ok(WrappedHttpResponse { response: response })
- }
-}
-
#[derive(Debug)]
struct LoadError {
pub url: ServoUrl,
@@ -217,7 +190,6 @@ impl LoadError {
#[derive(Eq, PartialEq, Debug)]
enum LoadErrorType {
Connection { reason: String },
- ConnectionAborted { reason: String },
Ssl { reason: String },
}
@@ -231,7 +203,6 @@ impl Error for LoadErrorType {
fn description(&self) -> &str {
match *self {
LoadErrorType::Connection { ref reason } => reason,
- LoadErrorType::ConnectionAborted { ref reason } => reason,
LoadErrorType::Ssl { ref reason } => reason,
}
}
@@ -526,22 +497,31 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
let send_start = precise_time_ms();
- let maybe_response = req.send(request_body);
+ let mut request_writer = match req.request.start() {
+ Ok(streaming) => streaming,
+ Err(e) => return Err(LoadError::new(connection_url,
+ LoadErrorType::Connection { reason: e.description().to_owned() })),
+ };
- let send_end = precise_time_ms();
+ 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() }))
+ }
+ }
- let response = match maybe_response {
- Ok(r) => r,
- Err(e) => {
- if let LoadErrorType::ConnectionAborted { reason } = e.error {
- debug!("connection aborted ({:?}), possibly stale, trying new connection", reason);
- continue;
- } else {
- return Err(e)
- }
+ let response = match request_writer.send() {
+ Ok(w) => w,
+ Err(HttpError::Io(ref io_error)) if io_error.kind() == io::ErrorKind::ConnectionAborted => {
+ 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() })),
};
+ let send_end = precise_time_ms();
+
let msg = if let Some(request_id) = request_id {
if let Some(pipeline_id) = *pipeline_id {
Some(prepare_devtools_request(
@@ -558,8 +538,7 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory,
None
};
- // if no ConnectionAborted, break the loop
- return Ok((response, msg));
+ return Ok((WrappedHttpResponse { response: response }, msg));
}
}
@@ -1113,7 +1092,6 @@ fn http_network_fetch(request: Rc<Request>,
Ok(wrapped_response) => wrapped_response,
Err(error) => {
let error = match error.error {
- LoadErrorType::ConnectionAborted { .. } => unreachable!(),
LoadErrorType::Ssl { reason } => NetworkError::SslValidation(error.url, reason),
e => NetworkError::Internal(e.description().to_owned())
};