servo: Merge #14741 - Reuse the http connector pool between fetches (from mattnenterprise:use-http-connection-pool); r=jdm
authorMatt McCoy <mattnenterprise@yahoo.com>
Tue, 27 Dec 2016 07:59:22 -0800
changeset 478599 7ad8391097b045c4aed972b1fa8f967c4c451f5c
parent 478598 a40edc66097890deec8274ff093c374f5eeedf74
child 478600 50b3f89cc07050ac88173b769f45a24da24f57fe
push id44079
push userbmo:gps@mozilla.com
push dateSat, 04 Feb 2017 00:14:49 +0000
reviewersjdm
servo: Merge #14741 - Reuse the http connector pool between fetches (from mattnenterprise:use-http-connection-pool); r=jdm <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #14697 <!-- Either: --> - [x] There are tests for these changes <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 7e3c9e21978b638b8f17192500251843f3743d1c
servo/components/net/http_loader.rs
servo/components/net/resource_thread.rs
--- a/servo/components/net/http_loader.rs
+++ b/servo/components/net/http_loader.rs
@@ -67,25 +67,27 @@ fn read_block<R: Read>(reader: &mut R) -
     }
 }
 
 pub struct HttpState {
     pub hsts_list: Arc<RwLock<HstsList>>,
     pub cookie_jar: Arc<RwLock<CookieStorage>>,
     pub auth_cache: Arc<RwLock<AuthCache>>,
     pub blocked_content: Arc<Option<RuleList>>,
+    pub connector_pool: Arc<Pool<Connector>>,
 }
 
 impl HttpState {
     pub fn new() -> HttpState {
         HttpState {
             hsts_list: Arc::new(RwLock::new(HstsList::new())),
             cookie_jar: Arc::new(RwLock::new(CookieStorage::new(150))),
             auth_cache: Arc::new(RwLock::new(AuthCache::new())),
             blocked_content: Arc::new(None),
+            connector_pool: create_http_connector(),
         }
     }
 }
 
 fn precise_time_ms() -> u64 {
     time::precise_time_ns() / (1000 * 1000)
 }
 
@@ -1016,25 +1018,25 @@ fn http_network_fetch(request: Rc<Reques
                       -> Response {
     // TODO: Implement HTTP network fetch spec
 
     // Step 1
     // nothing to do here, since credentials_flag is already a boolean
 
     // Step 2
     // TODO be able to create connection using current url's origin and credentials
-    let connection = create_http_connector();
 
     // Step 3
     // TODO be able to tell if the connection is a failure
 
     // Step 4
     let factory = NetworkHttpRequestFactory {
-        connector: connection,
+        connector: context.state.connector_pool.clone(),
     };
+
     let url = request.current_url();
 
     let request_id = context.devtools_chan.as_ref().map(|_| {
         uuid::Uuid::new_v4().simple().to_string()
     });
 
     // XHR uses the default destination; other kinds of fetches (which haven't been implemented yet)
     // do not. Once we support other kinds of fetches we'll need to be more fine grained here
--- a/servo/components/net/resource_thread.rs
+++ b/servo/components/net/resource_thread.rs
@@ -320,16 +320,17 @@ impl CoreResourceManager {
              init: RequestInit,
              mut sender: IpcSender<FetchResponseMsg>,
              group: &ResourceGroup) {
         let http_state = HttpState {
             hsts_list: group.hsts_list.clone(),
             cookie_jar: group.cookie_jar.clone(),
             auth_cache: group.auth_cache.clone(),
             blocked_content: BLOCKED_CONTENT_RULES.clone(),
+            connector_pool: group.connector.clone(),
         };
         let ua = self.user_agent.clone();
         let dc = self.devtools_chan.clone();
         let filemanager = self.filemanager.clone();
         thread::Builder::new().name(format!("fetch thread for {}", init.url)).spawn(move || {
             let request = Request::from_init(init);
             // XXXManishearth: Check origin against pipeline id (also ensure that the mode is allowed)
             // todo load context / mimesniff in fetch