From ba132e0b4ce29dfb5b1bf6a23cbf7ae5bdd6ca20 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 5 Apr 2017 16:44:28 -0400 Subject: [PATCH] Remove unnecessary NetworkHttpRequestFactory abstraction. --- components/net/http_loader.rs | 44 ++++++++--------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 3c09fc4ce7c4..e89bd86d1405 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -15,7 +15,6 @@ use hsts::HstsList; use hyper::Error as HttpError; use hyper::LanguageTag; use hyper::client::{Pool, Request as HyperRequest, Response as HyperResponse}; -use hyper::client::pool::PooledStream; use hyper::header::{Accept, AccessControlAllowCredentials, AccessControlAllowHeaders}; use hyper::header::{AccessControlAllowMethods, AccessControlAllowOrigin}; use hyper::header::{AccessControlMaxAge, AccessControlRequestHeaders}; @@ -27,9 +26,7 @@ use hyper::header::{IfUnmodifiedSince, IfModifiedSince, IfNoneMatch, Location}; use hyper::header::{Pragma, Quality, QualityItem, Referer, SetCookie}; use hyper::header::{UserAgent, q, qitem}; use hyper::method::Method; -use hyper::net::{Fresh, HttpStream, HttpsStream, NetworkConnector}; use hyper::status::StatusCode; -use hyper_openssl::SslStream; use hyper_serde::Serde; use log; use msg::constellation_msg::PipelineId; @@ -120,29 +117,6 @@ impl WrappedHttpResponse { } } -struct NetworkHttpRequestFactory { - pub connector: Arc>, -} - -impl NetworkConnector for NetworkHttpRequestFactory { - type Stream = PooledStream>>; - - fn connect(&self, host: &str, port: u16, scheme: &str) -> Result { - self.connector.connect(host, port, scheme) - } -} - -impl NetworkHttpRequestFactory { - fn create(&self, url: ServoUrl, method: Method, headers: Headers) - -> Result, NetworkError> { - let connection = HyperRequest::with_connector(method, url.clone().into_url(), self); - let mut request = connection.map_err(|e| NetworkError::from_hyper_error(&url, e))?; - *request.headers_mut() = headers; - - Ok(request) - } -} - // Step 3 of https://fetch.spec.whatwg.org/#concept-fetch. pub fn set_default_accept(type_: Type, destination: Destination, headers: &mut Headers) { if headers.has::() { @@ -415,7 +389,7 @@ fn auth_from_cache(auth_cache: &RwLock, origin: &ImmutableOrigin) -> } } -fn obtain_response(request_factory: &NetworkHttpRequestFactory, +fn obtain_response(connector: Arc>, url: &ServoUrl, method: &Method, request_headers: &Headers, @@ -466,8 +440,14 @@ fn obtain_response(request_factory: &NetworkHttpRequestFactory, let connect_start = precise_time_ms(); - let request = try!(request_factory.create(url.clone(), method.clone(), - headers.clone())); + let request = HyperRequest::with_connector(method.clone(), + url.clone().into_url(), + &*connector); + let mut request = match request { + Ok(request) => request, + Err(e) => return Err(NetworkError::from_hyper_error(&url, e)), + }; + *request.headers_mut() = headers.clone(); let connect_end = precise_time_ms(); @@ -1089,10 +1069,6 @@ fn http_network_fetch(request: &Request, // TODO be able to tell if the connection is a failure // Step 4 - let factory = NetworkHttpRequestFactory { - connector: context.connector.clone(), - }; - let url = request.current_url(); let request_id = context.devtools_chan.as_ref().map(|_| { @@ -1103,7 +1079,7 @@ fn http_network_fetch(request: &Request, // 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 let is_xhr = request.destination == Destination::None; - let wrapped_response = obtain_response(&factory, &url, &request.method, + let wrapped_response = obtain_response(context.connector.clone(), &url, &request.method, &request.headers, &request.body, &request.method, &request.pipeline_id, request.redirect_count + 1,