Auto merge of #10672 - frewsxcv:net-network, r=KiChjang

Improvements to network preferences, HTTP redirection limiting.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10672)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-19 04:06:25 +05:30
commit 80662f1e4e
7 changed files with 20 additions and 13 deletions

View file

@ -423,7 +423,7 @@ impl FontCacheThread {
// derived from http://stackoverflow.com/a/10864297/3830 // derived from http://stackoverflow.com/a/10864297/3830
fn is_supported_font_type(toplevel: &TopLevel, sublevel: &SubLevel) -> bool { fn is_supported_font_type(toplevel: &TopLevel, sublevel: &SubLevel) -> bool {
if !prefs::get_pref("net.mime.sniff").as_boolean().unwrap_or(false) { if !prefs::get_pref("network.mime.sniff").as_boolean().unwrap_or(false) {
return true; return true;
} }

View file

@ -44,6 +44,7 @@ use time::Tm;
#[cfg(any(target_os = "macos", target_os = "linux"))] #[cfg(any(target_os = "macos", target_os = "linux"))]
use tinyfiledialogs; use tinyfiledialogs;
use url::Url; use url::Url;
use util::prefs;
use util::resource_files::resources_dir_path; use util::resource_files::resources_dir_path;
use util::thread::spawn_named; use util::thread::spawn_named;
use uuid; use uuid;
@ -165,7 +166,7 @@ fn load_for_consumer(load_data: LoadData,
Err(LoadError::Connection(url, e)) => { Err(LoadError::Connection(url, e)) => {
send_error(url, e, start_chan) send_error(url, e, start_chan)
} }
Err(LoadError::MaxRedirects(url)) => { Err(LoadError::MaxRedirects(url, _)) => {
send_error(url, "too many redirects".to_owned(), start_chan) send_error(url, "too many redirects".to_owned(), start_chan)
} }
Err(LoadError::Cors(url, msg)) | Err(LoadError::Cors(url, msg)) |
@ -335,7 +336,7 @@ pub enum LoadError {
Ssl(Url, String), Ssl(Url, String),
InvalidRedirect(Url, String), InvalidRedirect(Url, String),
Decoding(Url, String), Decoding(Url, String),
MaxRedirects(Url), MaxRedirects(Url, u32), // u32 indicates number of redirects that occurred
ConnectionAborted(String), ConnectionAborted(String),
Cancelled(Url, String), Cancelled(Url, String),
} }
@ -726,10 +727,7 @@ pub fn load<A, B>(load_data: LoadData,
user_agent: String, user_agent: String,
cancel_listener: &CancellationListener) cancel_listener: &CancellationListener)
-> Result<StreamedResponse<A::R>, LoadError> where A: HttpRequest + 'static, B: UIProvider { -> Result<StreamedResponse<A::R>, LoadError> where A: HttpRequest + 'static, B: UIProvider {
// FIXME: At the time of writing this FIXME, servo didn't have any central let max_redirects = prefs::get_pref("network.http.redirection-limit").as_i64().unwrap() as u32;
// location for configuration. If you're reading this and such a
// repository DOES exist, please update this constant to use it.
let max_redirects = 50;
let mut iters = 0; let mut iters = 0;
// URL of the document being loaded, as seen by all the higher-level code. // URL of the document being loaded, as seen by all the higher-level code.
let mut doc_url = load_data.url.clone(); let mut doc_url = load_data.url.clone();
@ -761,7 +759,7 @@ pub fn load<A, B>(load_data: LoadData,
} }
if iters > max_redirects { if iters > max_redirects {
return Err(LoadError::MaxRedirects(doc_url)); return Err(LoadError::MaxRedirects(doc_url, iters - 1));
} }
if &*doc_url.scheme != "http" && &*doc_url.scheme != "https" { if &*doc_url.scheme != "http" && &*doc_url.scheme != "https" {

View file

@ -77,7 +77,7 @@ pub fn start_sending_sniffed_opt(start_chan: LoadConsumer, mut metadata: Metadat
classifier: Arc<MIMEClassifier>, partial_body: &[u8], classifier: Arc<MIMEClassifier>, partial_body: &[u8],
context: LoadContext) context: LoadContext)
-> Result<ProgressSender, ()> { -> Result<ProgressSender, ()> {
if prefs::get_pref("net.mime.sniff").as_boolean().unwrap_or(false) { if prefs::get_pref("network.mime.sniff").as_boolean().unwrap_or(false) {
// TODO: should be calculated in the resource loader, from pull requeset #4094 // TODO: should be calculated in the resource loader, from pull requeset #4094
let mut no_sniff = NoSniffFlag::OFF; let mut no_sniff = NoSniffFlag::OFF;
let mut check_for_apache_bug = ApacheBugFlag::OFF; let mut check_for_apache_bug = ApacheBugFlag::OFF;

View file

@ -49,7 +49,8 @@
"layout.text-orientation.enabled": false, "layout.text-orientation.enabled": false,
"layout.viewport.enabled": false, "layout.viewport.enabled": false,
"layout.writing-mode.enabled": false, "layout.writing-mode.enabled": false,
"net.mime.sniff": false, "network.http.redirection-limit": 20,
"network.mime.sniff": false,
"shell.native-titlebar.enabled": true, "shell.native-titlebar.enabled": true,
"shell.homepage": "http://servo.org" "shell.homepage": "http://servo.org"
} }

View file

@ -28,6 +28,7 @@ use std::io::{self, Write, Read, Cursor};
use std::sync::mpsc::Receiver; use std::sync::mpsc::Receiver;
use std::sync::{Arc, mpsc, RwLock}; use std::sync::{Arc, mpsc, RwLock};
use url::Url; use url::Url;
use util::prefs;
const DEFAULT_USER_AGENT: &'static str = "Test-agent"; const DEFAULT_USER_AGENT: &'static str = "Test-agent";
@ -1103,13 +1104,20 @@ fn test_load_errors_when_there_is_too_many_redirects() {
let http_state = HttpState::new(); let http_state = HttpState::new();
let ui_provider = TestProvider::new(); let ui_provider = TestProvider::new();
let redirect_limit = 13.;
prefs::set_pref("network.http.redirection-limit",
prefs::PrefValue::Number(redirect_limit));
match load(load_data, &ui_provider, &http_state, None, &Factory, match load(load_data, &ui_provider, &http_state, None, &Factory,
DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) { DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) {
Err(LoadError::MaxRedirects(url)) => { Err(LoadError::MaxRedirects(url, num_redirects)) => {
assert_eq!(num_redirects, redirect_limit as u32);
assert_eq!(url.domain().unwrap(), "mozilla.com") assert_eq!(url.domain().unwrap(), "mozilla.com")
}, },
_ => panic!("expected max redirects to fail") _ => panic!("expected max redirects to fail")
} }
prefs::reset_pref("network.http.redirection-limit");
} }
#[test] #[test]

View file

@ -8,7 +8,7 @@ use util::prefs::{PrefValue, extend_prefs, read_prefs_from_file, get_pref, set_p
fn test_create_pref() { fn test_create_pref() {
let json_str = "{\ let json_str = "{\
\"layout.writing-mode.enabled\": true,\ \"layout.writing-mode.enabled\": true,\
\"net.mime.sniff\": false,\ \"network.mime.sniff\": false,\
\"shell.homepage\": \"http://servo.org\"\ \"shell.homepage\": \"http://servo.org\"\
}"; }";

View file

@ -1,3 +1,3 @@
[mime_sniffing_font_context.html] [mime_sniffing_font_context.html]
type: testharness type: testharness
prefs: [net.mime.sniff:true] prefs: [network.mime.sniff:true]