mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
M1456, Implement MIME sniffing initial Step
This commit is contained in:
parent
c5e1b0d32e
commit
7472564bf6
3 changed files with 56 additions and 2 deletions
|
@ -37,6 +37,7 @@ pub mod data_loader;
|
||||||
pub mod image_cache_task;
|
pub mod image_cache_task;
|
||||||
pub mod local_image_cache;
|
pub mod local_image_cache;
|
||||||
pub mod resource_task;
|
pub mod resource_task;
|
||||||
|
mod sniffer_task;
|
||||||
|
|
||||||
/// An implementation of the [Fetch spec](http://fetch.spec.whatwg.org/)
|
/// An implementation of the [Fetch spec](http://fetch.spec.whatwg.org/)
|
||||||
pub mod fetch {
|
pub mod fetch {
|
||||||
|
|
|
@ -8,6 +8,7 @@ use about_loader;
|
||||||
use data_loader;
|
use data_loader;
|
||||||
use file_loader;
|
use file_loader;
|
||||||
use http_loader;
|
use http_loader;
|
||||||
|
use sniffer_task;
|
||||||
|
|
||||||
use std::comm::{channel, Receiver, Sender};
|
use std::comm::{channel, Receiver, Sender};
|
||||||
use http::headers::content_type::MediaType;
|
use http::headers::content_type::MediaType;
|
||||||
|
@ -177,7 +178,6 @@ struct ResourceManager {
|
||||||
user_agent: Option<String>,
|
user_agent: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl ResourceManager {
|
impl ResourceManager {
|
||||||
fn new(from_client: Receiver<ControlMsg>, user_agent: Option<String>) -> ResourceManager {
|
fn new(from_client: Receiver<ControlMsg>, user_agent: Option<String>) -> ResourceManager {
|
||||||
ResourceManager {
|
ResourceManager {
|
||||||
|
@ -206,6 +206,12 @@ impl ResourceManager {
|
||||||
let mut load_data = load_data;
|
let mut load_data = load_data;
|
||||||
load_data.headers.user_agent = self.user_agent.clone();
|
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() {
|
let loader = match load_data.url.scheme.as_slice() {
|
||||||
"file" => file_loader::factory,
|
"file" => file_loader::factory,
|
||||||
"http" | "https" => http_loader::factory,
|
"http" | "https" => http_loader::factory,
|
||||||
|
@ -219,7 +225,8 @@ impl ResourceManager {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
debug!("resource_task: loading url: {:s}", load_data.url.serialize());
|
debug!("resource_task: loading url: {:s}", load_data.url.serialize());
|
||||||
loader(load_data, start_chan);
|
|
||||||
|
loader(load_data, sniffer_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
46
components/net/sniffer_task.rs
Normal file
46
components/net/sniffer_task.rs
Normal file
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue