servo: Merge #14106 - Deindent some of the code in http_network_fetch (from servo:deindent-http-network-fetch); r=nox
authorMs2ger <Ms2ger@gmail.com>
Tue, 08 Nov 2016 00:03:24 -0600
changeset 340094 1dc43f2bae39c8ffdd42423644395fac75425a2f
parent 340093 33cc8ed60a232e003e907177e6ee0b17e8739bc2
child 340095 b96bc76b76c90630a73938cb6fcd17276fada9df
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnox
servo: Merge #14106 - Deindent some of the code in http_network_fetch (from servo:deindent-http-network-fetch); r=nox Source-Repo: https://github.com/servo/servo Source-Revision: 32a953f0bacb245e507d2a5125907b5ce724e332
servo/components/net/fetch/methods.rs
--- a/servo/components/net/fetch/methods.rs
+++ b/servo/components/net/fetch/methods.rs
@@ -1010,109 +1010,109 @@ fn http_network_fetch<UI: 'static + UIPr
     let is_xhr = request.destination == Destination::None;
     let wrapped_response = obtain_response(&factory, &url, &request.method.borrow(),
                                            &request.headers.borrow(),
                                            &cancellation_listener, &request.body.borrow(), &request.method.borrow(),
                                            &request.pipeline_id.get(), request.redirect_count.get() + 1,
                                            request_id.as_ref().map(Deref::deref), is_xhr);
 
     let pipeline_id = request.pipeline_id.get();
-    let mut response = Response::new();
-    match wrapped_response {
-        Ok((res, msg)) => {
-            response.url = Some(url.clone());
-            response.status = Some(res.response.status);
-            response.raw_status = Some((res.response.status_raw().0,
-                                        res.response.status_raw().1.as_bytes().to_vec()));
-            response.headers = res.response.headers.clone();
-            response.referrer = request.referrer.borrow().to_url().cloned();
-
-            let res_body = response.body.clone();
-
-            // We're about to spawn a thread to be waited on here
-            *done_chan = Some(channel());
-            let meta = match response.metadata().expect("Response metadata should exist at this stage") {
-                FetchMetadata::Unfiltered(m) => m,
-                FetchMetadata::Filtered { unsafe_, .. } => unsafe_
-            };
-            let done_sender = done_chan.as_ref().map(|ch| ch.0.clone());
-            let devtools_sender = context.devtools_chan.clone();
-            let meta_status = meta.status.clone();
-            let meta_headers = meta.headers.clone();
-            spawn_named(format!("fetch worker thread"), move || {
-                match StreamedResponse::from_http_response(box res, meta) {
-                    Ok(mut res) => {
-                        *res_body.lock().unwrap() = ResponseBody::Receiving(vec![]);
-
-                        if let Some(ref sender) = devtools_sender {
-                            if let Some(m) = msg {
-                                send_request_to_devtools(m, &sender);
-                            }
-
-                            // --- Tell devtools that we got a response
-                            // Send an HttpResponse message to devtools with the corresponding request_id
-                            if let Some(pipeline_id) = pipeline_id {
-                                send_response_to_devtools(
-                                    &sender, request_id.unwrap(),
-                                    meta_headers.map(Serde::into_inner),
-                                    meta_status,
-                                    pipeline_id);
-                            }
-                        }
-
-                        loop {
-                            match read_block(&mut res) {
-                                Ok(ReadResult::Payload(chunk)) => {
-                                    if let ResponseBody::Receiving(ref mut body) = *res_body.lock().unwrap() {
-                                        body.extend_from_slice(&chunk);
-                                        if let Some(ref sender) = done_sender {
-                                            let _ = sender.send(Data::Payload(chunk));
-                                        }
-                                    }
-                                },
-                                Ok(ReadResult::EOF) | Err(_) => {
-                                    let mut empty_vec = Vec::new();
-                                    let completed_body = match *res_body.lock().unwrap() {
-                                        ResponseBody::Receiving(ref mut body) => {
-                                            // avoid cloning the body
-                                            swap(body, &mut empty_vec);
-                                            empty_vec
-                                        },
-                                        _ => empty_vec,
-                                    };
-                                    *res_body.lock().unwrap() = ResponseBody::Done(completed_body);
-                                    if let Some(ref sender) = done_sender {
-                                        let _ = sender.send(Data::Done);
-                                    }
-                                    break;
-                                }
-                            }
-                        }
-                    }
-                    Err(_) => {
-                        // XXXManishearth we should propagate this error somehow
-                        *res_body.lock().unwrap() = ResponseBody::Done(vec![]);
-                        if let Some(ref sender) = done_sender {
-                            let _ = sender.send(Data::Done);
-                        }
-                    }
-                }
-            });
-        },
+    let (res, msg) = match wrapped_response {
+        Ok(wrapped_response) => wrapped_response,
         Err(error) => {
             let error = match error.error {
                 LoadErrorType::ConnectionAborted { .. } => unreachable!(),
                 LoadErrorType::Ssl { reason } => NetworkError::SslValidation(error.url, reason),
                 LoadErrorType::Cancelled => NetworkError::LoadCancelled,
                 e => NetworkError::Internal(e.description().to_owned())
             };
             return Response::network_error(error);
         }
     };
 
+    let mut response = Response::new();
+    response.url = Some(url.clone());
+    response.status = Some(res.response.status);
+    response.raw_status = Some((res.response.status_raw().0,
+                                res.response.status_raw().1.as_bytes().to_vec()));
+    response.headers = res.response.headers.clone();
+    response.referrer = request.referrer.borrow().to_url().cloned();
+
+    let res_body = response.body.clone();
+
+    // We're about to spawn a thread to be waited on here
+    *done_chan = Some(channel());
+    let meta = match response.metadata().expect("Response metadata should exist at this stage") {
+        FetchMetadata::Unfiltered(m) => m,
+        FetchMetadata::Filtered { unsafe_, .. } => unsafe_
+    };
+    let done_sender = done_chan.as_ref().map(|ch| ch.0.clone());
+    let devtools_sender = context.devtools_chan.clone();
+    let meta_status = meta.status.clone();
+    let meta_headers = meta.headers.clone();
+    spawn_named(format!("fetch worker thread"), move || {
+        match StreamedResponse::from_http_response(box res, meta) {
+            Ok(mut res) => {
+                *res_body.lock().unwrap() = ResponseBody::Receiving(vec![]);
+
+                if let Some(ref sender) = devtools_sender {
+                    if let Some(m) = msg {
+                        send_request_to_devtools(m, &sender);
+                    }
+
+                    // --- Tell devtools that we got a response
+                    // Send an HttpResponse message to devtools with the corresponding request_id
+                    if let Some(pipeline_id) = pipeline_id {
+                        send_response_to_devtools(
+                            &sender, request_id.unwrap(),
+                            meta_headers.map(Serde::into_inner),
+                            meta_status,
+                            pipeline_id);
+                    }
+                }
+
+                loop {
+                    match read_block(&mut res) {
+                        Ok(ReadResult::Payload(chunk)) => {
+                            if let ResponseBody::Receiving(ref mut body) = *res_body.lock().unwrap() {
+                                body.extend_from_slice(&chunk);
+                                if let Some(ref sender) = done_sender {
+                                    let _ = sender.send(Data::Payload(chunk));
+                                }
+                            }
+                        },
+                        Ok(ReadResult::EOF) | Err(_) => {
+                            let mut empty_vec = Vec::new();
+                            let completed_body = match *res_body.lock().unwrap() {
+                                ResponseBody::Receiving(ref mut body) => {
+                                    // avoid cloning the body
+                                    swap(body, &mut empty_vec);
+                                    empty_vec
+                                },
+                                _ => empty_vec,
+                            };
+                            *res_body.lock().unwrap() = ResponseBody::Done(completed_body);
+                            if let Some(ref sender) = done_sender {
+                                let _ = sender.send(Data::Done);
+                            }
+                            break;
+                        }
+                    }
+                }
+            }
+            Err(_) => {
+                // XXXManishearth we should propagate this error somehow
+                *res_body.lock().unwrap() = ResponseBody::Done(vec![]);
+                if let Some(ref sender) = done_sender {
+                    let _ = sender.send(Data::Done);
+                }
+            }
+        }
+    });
+
         // TODO these substeps aren't possible yet
         // Substep 1
 
         // Substep 2
 
     // TODO Determine if response was retrieved over HTTPS
     // TODO Servo needs to decide what ciphers are to be treated as "deprecated"
     response.https_state = HttpsState::None;