servo: Merge #14570 - Remove some dead code related to the old network stack (from servo:resource-thread); r=emilio
authorMs2ger <Ms2ger@gmail.com>
Wed, 14 Dec 2016 07:31:41 -0800
changeset 478503 8fb10a3f223485259d33e80b82d279b5f2e49adf
parent 478502 4f041c806f946dd5f869d3a05449b71bb6b89210
child 478504 c37b67408e8cccf968f80e3f05664767a0ff02a5
push id44079
push userbmo:gps@mozilla.com
push dateSat, 04 Feb 2017 00:14:49 +0000
reviewersemilio
servo: Merge #14570 - Remove some dead code related to the old network stack (from servo:resource-thread); r=emilio Source-Repo: https://github.com/servo/servo Source-Revision: 385d9bc1fa41e11560e2a7c26e9916350b0a66e2
servo/components/net/resource_thread.rs
servo/components/net_traits/lib.rs
--- a/servo/components/net/resource_thread.rs
+++ b/servo/components/net/resource_thread.rs
@@ -9,27 +9,23 @@ use cookie;
 use cookie_rs;
 use cookie_storage::CookieStorage;
 use devtools_traits::DevtoolsControlMsg;
 use fetch::methods::{FetchContext, fetch};
 use filemanager_thread::{FileManager, TFDProvider};
 use hsts::HstsList;
 use http_loader::HttpState;
 use hyper::client::pool::Pool;
-use hyper::header::{ContentType, Header, SetCookie};
-use hyper::mime::{Mime, SubLevel, TopLevel};
+use hyper::header::{Header, SetCookie};
 use hyper_serde::Serde;
 use ipc_channel::ipc::{self, IpcReceiver, IpcReceiverSet, IpcSender};
-use mime_classifier::{ApacheBugFlag, MimeClassifier, NoSniffFlag};
-use net_traits::{CookieSource, CoreResourceThread, Metadata, ProgressMsg};
-use net_traits::{CoreResourceMsg, FetchResponseMsg, FetchTaskTarget, LoadConsumer};
-use net_traits::{CustomResponseMediator, LoadResponse, NetworkError, ResourceId};
+use net_traits::{CookieSource, CoreResourceThread};
+use net_traits::{CoreResourceMsg, FetchResponseMsg, FetchTaskTarget};
+use net_traits::{CustomResponseMediator, ResourceId};
 use net_traits::{ResourceThreads, WebSocketCommunicate, WebSocketConnectData};
-use net_traits::LoadContext;
-use net_traits::ProgressMsg::Done;
 use net_traits::request::{Request, RequestInit};
 use net_traits::storage_thread::StorageThreadMsg;
 use profile_traits::time::ProfilerChan;
 use rustc_serialize::{Decodable, Encodable};
 use rustc_serialize::json;
 use servo_url::ServoUrl;
 use std::borrow::{Cow, ToOwned};
 use std::collections::HashMap;
@@ -37,110 +33,29 @@ use std::error::Error;
 use std::fs::File;
 use std::io::prelude::*;
 use std::ops::Deref;
 use std::path::{Path, PathBuf};
 use std::rc::Rc;
 use std::sync::{Arc, RwLock};
 use std::sync::mpsc::Sender;
 use storage_thread::StorageThreadFactory;
-use util::prefs::PREFS;
 use util::thread::spawn_named;
 use websocket_loader;
 
 const TFD_PROVIDER: &'static TFDProvider = &TFDProvider;
 
-pub enum ProgressSender {
-    Channel(IpcSender<ProgressMsg>),
-}
-
 #[derive(Clone)]
 pub struct ResourceGroup {
     cookie_jar: Arc<RwLock<CookieStorage>>,
     auth_cache: Arc<RwLock<AuthCache>>,
     hsts_list: Arc<RwLock<HstsList>>,
     connector: Arc<Pool<Connector>>,
 }
 
-impl ProgressSender {
-    //XXXjdm return actual error
-    pub fn send(&self, msg: ProgressMsg) -> Result<(), ()> {
-        match *self {
-            ProgressSender::Channel(ref c) => c.send(msg).map_err(|_| ()),
-        }
-    }
-}
-
-pub fn send_error(url: ServoUrl, err: NetworkError, start_chan: LoadConsumer) {
-    let mut metadata: Metadata = Metadata::default(url);
-    metadata.status = None;
-
-    if let Ok(p) = start_sending_opt(start_chan, metadata) {
-        p.send(Done(Err(err))).unwrap();
-    }
-}
-
-/// For use by loaders in responding to a Load message that allows content sniffing.
-pub fn start_sending_sniffed_opt(start_chan: LoadConsumer, mut metadata: Metadata,
-                                 classifier: Arc<MimeClassifier>, partial_body: &[u8],
-                                 context: LoadContext)
-                                 -> Result<ProgressSender, ()> {
-    if PREFS.get("network.mime.sniff").as_boolean().unwrap_or(false) {
-        // TODO: should be calculated in the resource loader, from pull requeset #4094
-        let mut no_sniff = NoSniffFlag::Off;
-        let mut check_for_apache_bug = ApacheBugFlag::Off;
-
-        if let Some(ref headers) = metadata.headers {
-            if let Some(ref content_type) = headers.get_raw("content-type").and_then(|c| c.last()) {
-                check_for_apache_bug = ApacheBugFlag::from_content_type(content_type)
-            }
-            if let Some(ref raw_content_type_options) = headers.get_raw("X-content-type-options") {
-                if raw_content_type_options.iter().any(|ref opt| *opt == b"nosniff") {
-                    no_sniff = NoSniffFlag::On
-                }
-            }
-        }
-
-        let supplied_type =
-            metadata.content_type.as_ref().map(|&Serde(ContentType(Mime(ref toplevel, ref sublevel, _)))| {
-            (toplevel.to_owned(), format!("{}", sublevel))
-        });
-        let (toplevel, sublevel) = classifier.classify(context,
-                                                       no_sniff,
-                                                       check_for_apache_bug,
-                                                       &supplied_type,
-                                                       &partial_body);
-        let mime_tp: TopLevel = toplevel.into();
-        let mime_sb: SubLevel = sublevel.parse().unwrap();
-        metadata.content_type =
-            Some(Serde(ContentType(Mime(mime_tp, mime_sb, vec![]))));
-    }
-
-    start_sending_opt(start_chan, metadata)
-}
-
-/// For use by loaders in responding to a Load message.
-/// It takes an optional NetworkError, so that we can extract the SSL Validation errors
-/// and take it to the HTML parser
-fn start_sending_opt(start_chan: LoadConsumer, metadata: Metadata) -> Result<ProgressSender, ()> {
-    match start_chan {
-        LoadConsumer::Channel(start_chan) => {
-            let (progress_chan, progress_port) = ipc::channel().unwrap();
-            let result = start_chan.send(LoadResponse {
-                metadata: metadata,
-                progress_port: progress_port,
-            });
-            match result {
-                Ok(_) => Ok(ProgressSender::Channel(progress_chan)),
-                Err(_) => Err(())
-            }
-        }
-    }
-}
-
 /// Returns a tuple of (public, private) senders to the new threads.
 pub fn new_resource_threads(user_agent: Cow<'static, str>,
                             devtools_chan: Option<Sender<DevtoolsControlMsg>>,
                             profiler_chan: ProfilerChan,
                             config_dir: Option<PathBuf>)
                             -> (ResourceThreads, ResourceThreads) {
     let (public_core, private_core) = new_core_resource_thread(
         user_agent,
--- a/servo/components/net_traits/lib.rs
+++ b/servo/components/net_traits/lib.rs
@@ -240,22 +240,16 @@ impl<T: FetchResponseListener> Action<T>
 
 impl<T: BluetoothResponseListener> Action<T> for BluetoothResponseResult {
     /// Execute the default action on a provided listener.
     fn process(self, listener: &mut T) {
         listener.response(self)
     }
 }
 
-/// A wrapper for a network load that can either be channel or event-based.
-#[derive(Deserialize, Serialize)]
-pub enum LoadConsumer {
-    Channel(IpcSender<LoadResponse>),
-}
-
 /// Handle to a resource thread
 pub type CoreResourceThread = IpcSender<CoreResourceMsg>;
 
 pub type IpcSendResult = Result<(), IOError>;
 
 /// Abstraction of the ability to send a particular type of message,
 /// used by net_traits::ResourceThreads to ease the use its IpcSender sub-fields
 /// XXX: If this trait will be used more in future, some auto derive might be appealing
@@ -396,29 +390,16 @@ pub fn fetch_async<F>(request: RequestIn
 {
     let (action_sender, action_receiver) = ipc::channel().unwrap();
     ROUTER.add_route(action_receiver.to_opaque(), box move |message| {
         f(message.to().unwrap());
     });
     core_resource_thread.send(CoreResourceMsg::Fetch(request, action_sender)).unwrap();
 }
 
-/// Message sent in response to `Load`.  Contains metadata, and a port
-/// for receiving the data.
-///
-/// Even if loading fails immediately, we send one of these and the
-/// progress_port will provide the error.
-#[derive(Serialize, Deserialize)]
-pub struct LoadResponse {
-    /// Metadata, such as from HTTP headers.
-    pub metadata: Metadata,
-    /// Port for reading data.
-    pub progress_port: IpcReceiver<ProgressMsg>,
-}
-
 #[derive(Clone, Deserialize, Serialize, HeapSizeOf)]
 pub struct ResourceCorsData {
     /// CORS Preflight flag
     pub preflight: bool,
     /// Origin of CORS Request
     pub origin: ServoUrl,
 }
 
@@ -494,25 +475,16 @@ impl Metadata {
 #[derive(PartialEq, Copy, Clone, Deserialize, Serialize)]
 pub enum CookieSource {
     /// An HTTP API
     HTTP,
     /// A non-HTTP API
     NonHTTP,
 }
 
-/// Messages sent in response to a `Load` message
-#[derive(PartialEq, Debug, Deserialize, Serialize)]
-pub enum ProgressMsg {
-    /// Binary data - there may be multiple of these
-    Payload(Vec<u8>),
-    /// Indicates loading is complete, either successfully or not
-    Done(Result<(), NetworkError>),
-}
-
 /// Convenience function for synchronously loading a whole resource.
 pub fn load_whole_resource(request: RequestInit,
                            core_resource_thread: &CoreResourceThread)
                            -> Result<(Metadata, Vec<u8>), NetworkError> {
     let (action_sender, action_receiver) = ipc::channel().unwrap();
     core_resource_thread.send(CoreResourceMsg::Fetch(request, action_sender)).unwrap();
 
     let mut buf = vec!();