Skip to content

Commit

Permalink
Remove unnecessary NetworkHttpRequestFactory abstraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Apr 6, 2017
1 parent e9fdc4c commit ba132e0
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions components/net/http_loader.rs
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -120,29 +117,6 @@ impl WrappedHttpResponse {
}
}

struct NetworkHttpRequestFactory {
pub connector: Arc<Pool<Connector>>,
}

impl NetworkConnector for NetworkHttpRequestFactory {
type Stream = PooledStream<HttpsStream<SslStream<HttpStream>>>;

fn connect(&self, host: &str, port: u16, scheme: &str) -> Result<Self::Stream, HttpError> {
self.connector.connect(host, port, scheme)
}
}

impl NetworkHttpRequestFactory {
fn create(&self, url: ServoUrl, method: Method, headers: Headers)
-> Result<HyperRequest<Fresh>, 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::<Accept>() {
Expand Down Expand Up @@ -415,7 +389,7 @@ fn auth_from_cache(auth_cache: &RwLock<AuthCache>, origin: &ImmutableOrigin) ->
}
}

fn obtain_response(request_factory: &NetworkHttpRequestFactory,
fn obtain_response(connector: Arc<Pool<Connector>>,
url: &ServoUrl,
method: &Method,
request_headers: &Headers,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(|_| {
Expand All @@ -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,
Expand Down

0 comments on commit ba132e0

Please sign in to comment.