Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M1456, Implement MIME sniffing initial Step #3766

Merged
merged 1 commit into from Nov 15, 2014
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -37,6 +37,7 @@ pub mod data_loader;
pub mod image_cache_task;
pub mod local_image_cache;
pub mod resource_task;
mod sniffer_task;

/// An implementation of the [Fetch spec](http://fetch.spec.whatwg.org/)
pub mod fetch {
@@ -8,6 +8,7 @@ use about_loader;
use data_loader;
use file_loader;
use http_loader;
use sniffer_task;

use std::comm::{channel, Receiver, Sender};
use http::headers::content_type::MediaType;
@@ -177,7 +178,6 @@ struct ResourceManager {
user_agent: Option<String>,
}


impl ResourceManager {
fn new(from_client: Receiver<ControlMsg>, user_agent: Option<String>) -> ResourceManager {
ResourceManager {
@@ -206,6 +206,12 @@ impl ResourceManager {
let mut load_data = load_data;
load_data.headers.user_agent = self.user_agent.clone();

// Create new communication channel, create new sniffer task,
// send all the data to the new sniffer task with the send
// end of the pipe, receive all the data.

let sniffer_task = sniffer_task::new_sniffer_task(start_chan.clone());

let loader = match load_data.url.scheme.as_slice() {
"file" => file_loader::factory,
"http" | "https" => http_loader::factory,
@@ -219,7 +225,8 @@ impl ResourceManager {
}
};
debug!("resource_task: loading url: {:s}", load_data.url.serialize());
loader(load_data, start_chan);

loader(load_data, sniffer_task);
}
}

@@ -0,0 +1,46 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! A task that sniffs data
use std::comm::{channel, Receiver, Sender, Disconnected};
use std::task::TaskBuilder;
use resource_task::{LoadResponse};

pub type SnifferTask = Sender<LoadResponse>;

pub fn new_sniffer_task(next_rx: Sender<LoadResponse>) -> SnifferTask {
let(sen, rec) = channel();
let builder = TaskBuilder::new().named("SnifferManager");
builder.spawn(proc(){
SnifferManager::new(rec).start(next_rx);
});
sen
}

struct SnifferManager {
data_receiver: Receiver<LoadResponse>,
}

impl SnifferManager {
fn new(data_receiver: Receiver <LoadResponse>) -> SnifferManager {
SnifferManager {
data_receiver: data_receiver,
}
}
}

impl SnifferManager {
fn start(&self, next_rx: Sender<LoadResponse>) {
loop {
match self.data_receiver.try_recv() {
Ok(snif_data) => next_rx.send(snif_data),
Err(e) => {
if e == Disconnected {
break
}
}
}
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.