Verify number of redirects when we reach limit.

This commit is contained in:
Corey Farwell 2016-04-17 16:53:59 -04:00
parent 8e14cbccc3
commit da0adeb0ac
2 changed files with 12 additions and 4 deletions

View file

@ -166,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)) |
@ -336,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),
} }
@ -759,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

@ -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]