mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Remove the sniffer task.
This commit is contained in:
parent
44930b0fb0
commit
2d730f2ae9
8 changed files with 60 additions and 101 deletions
|
@ -2,10 +2,10 @@
|
|||
* 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/. */
|
||||
|
||||
use net_traits::{ControlMsg, CookieSource, LoadData, Metadata};
|
||||
use net_traits::{ControlMsg, CookieSource, LoadData, LoadResponse, Metadata};
|
||||
use net_traits::ProgressMsg;
|
||||
use net_traits::ProgressMsg::{Payload, Done};
|
||||
use resource_task::{TargetedLoadResponse, start_sending_opt, ResponseSenders};
|
||||
use resource_task::start_sending_opt;
|
||||
|
||||
use log;
|
||||
use std::collections::HashSet;
|
||||
|
@ -31,36 +31,32 @@ use url::{Url, UrlParser};
|
|||
use std::borrow::ToOwned;
|
||||
|
||||
pub fn factory(cookies_chan: Sender<ControlMsg>)
|
||||
-> Box<Invoke<(LoadData, Sender<TargetedLoadResponse>)> + Send> {
|
||||
box move |(load_data, start_chan)| {
|
||||
spawn_named("http_loader".to_owned(), move || load(load_data, start_chan, cookies_chan))
|
||||
-> Box<Invoke<(LoadData,)> + Send> {
|
||||
box move |(load_data,)| {
|
||||
spawn_named("http_loader".to_owned(), move || load(load_data, cookies_chan))
|
||||
}
|
||||
}
|
||||
|
||||
fn send_error(url: Url, err: String, senders: ResponseSenders) {
|
||||
fn send_error(url: Url, err: String, start_chan: Sender<LoadResponse>) {
|
||||
let mut metadata: Metadata = Metadata::default(url);
|
||||
metadata.status = None;
|
||||
|
||||
match start_sending_opt(senders, metadata) {
|
||||
match start_sending_opt(start_chan, metadata) {
|
||||
Ok(p) => p.send(Done(Err(err))).unwrap(),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
||||
fn load(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>, cookies_chan: Sender<ControlMsg>) {
|
||||
fn load(mut load_data: LoadData, cookies_chan: Sender<ControlMsg>) {
|
||||
// FIXME: At the time of writing this FIXME, servo didn't have any central
|
||||
// location for configuration. If you're reading this and such a
|
||||
// repository DOES exist, please update this constant to use it.
|
||||
let max_redirects = 50u;
|
||||
let mut iters = 0u;
|
||||
let start_chan = load_data.consumer;
|
||||
let mut url = load_data.url.clone();
|
||||
let mut redirected_to = HashSet::new();
|
||||
|
||||
let senders = ResponseSenders {
|
||||
immediate_consumer: start_chan,
|
||||
eventual_consumer: load_data.consumer
|
||||
};
|
||||
|
||||
// If the URL is a view-source scheme then the scheme data contains the
|
||||
// real URL that should be used for which the source is to be viewed.
|
||||
// Change our existing URL to that and keep note that we are viewing
|
||||
|
@ -73,7 +69,7 @@ fn load(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>, cooki
|
|||
"http" | "https" => {}
|
||||
_ => {
|
||||
let s = format!("The {} scheme with view-source is not supported", url.scheme);
|
||||
send_error(url, s, senders);
|
||||
send_error(url, s, start_chan);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -84,7 +80,7 @@ fn load(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>, cooki
|
|||
iters = iters + 1;
|
||||
|
||||
if iters > max_redirects {
|
||||
send_error(url, "too many redirects".to_string(), senders);
|
||||
send_error(url, "too many redirects".to_string(), start_chan);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -92,7 +88,7 @@ fn load(mut load_data: LoadData, start_chan: Sender<TargetedLoadResponse>, cooki
|
|||
"http" | "https" => {}
|
||||
_ => {
|
||||
let s = format!("{} request, but we don't support that scheme", url.scheme);
|
||||
send_error(url, s, senders);
|
||||
send_error(url, s, start_chan);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -125,13 +121,13 @@ reason: \"certificate verify failed\" }]";
|
|||
) => {
|
||||
let mut image = resources_dir_path();
|
||||
image.push("badcert.html");
|
||||
let load_data = LoadData::new(Url::from_file_path(&*image).unwrap(), senders.eventual_consumer);
|
||||
file_loader::factory(load_data, senders.immediate_consumer);
|
||||
let load_data = LoadData::new(Url::from_file_path(&*image).unwrap(), start_chan);
|
||||
file_loader::factory(load_data);
|
||||
return;
|
||||
},
|
||||
Err(e) => {
|
||||
println!("{:?}", e);
|
||||
send_error(url, e.description().to_string(), senders);
|
||||
send_error(url, e.description().to_string(), start_chan);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -179,13 +175,13 @@ reason: \"certificate verify failed\" }]";
|
|||
let mut writer = match req.start() {
|
||||
Ok(w) => w,
|
||||
Err(e) => {
|
||||
send_error(url, e.description().to_string(), senders);
|
||||
send_error(url, e.description().to_string(), start_chan);
|
||||
return;
|
||||
}
|
||||
};
|
||||
match writer.write_all(&*data) {
|
||||
Err(e) => {
|
||||
send_error(url, e.description().to_string(), senders);
|
||||
send_error(url, e.description().to_string(), start_chan);
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
|
@ -200,7 +196,7 @@ reason: \"certificate verify failed\" }]";
|
|||
match req.start() {
|
||||
Ok(w) => w,
|
||||
Err(e) => {
|
||||
send_error(url, e.description().to_string(), senders);
|
||||
send_error(url, e.description().to_string(), start_chan);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +205,7 @@ reason: \"certificate verify failed\" }]";
|
|||
let mut response = match writer.send() {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
send_error(url, e.description().to_string(), senders);
|
||||
send_error(url, e.description().to_string(), start_chan);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -240,7 +236,7 @@ reason: \"certificate verify failed\" }]";
|
|||
Some(ref c) => {
|
||||
if c.preflight {
|
||||
// The preflight lied
|
||||
send_error(url, "Preflight fetch inconsistent with main fetch".to_string(), senders);
|
||||
send_error(url, "Preflight fetch inconsistent with main fetch".to_string(), start_chan);
|
||||
return;
|
||||
} else {
|
||||
// XXXManishearth There are some CORS-related steps here,
|
||||
|
@ -252,7 +248,7 @@ reason: \"certificate verify failed\" }]";
|
|||
let new_url = match UrlParser::new().base_url(&url).parse(&new_url) {
|
||||
Ok(u) => u,
|
||||
Err(e) => {
|
||||
send_error(url, e.to_string(), senders);
|
||||
send_error(url, e.to_string(), start_chan);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -268,7 +264,7 @@ reason: \"certificate verify failed\" }]";
|
|||
}
|
||||
|
||||
if redirected_to.contains(&url) {
|
||||
send_error(url, "redirect loop".to_string(), senders);
|
||||
send_error(url, "redirect loop".to_string(), start_chan);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -291,7 +287,7 @@ reason: \"certificate verify failed\" }]";
|
|||
metadata.headers = Some(adjusted_headers);
|
||||
metadata.status = Some(response.status_raw().clone());
|
||||
|
||||
let progress_chan = match start_sending_opt(senders, metadata) {
|
||||
let progress_chan = match start_sending_opt(start_chan, metadata) {
|
||||
Ok(p) => p,
|
||||
_ => return
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue