diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs index 5aca88e19eb..5473a83fce5 100644 --- a/components/net/http_loader.rs +++ b/components/net/http_loader.rs @@ -155,8 +155,7 @@ fn load_for_consumer(load_data: LoadData, }; let ui_provider = TFDProvider; - let context = load_data.context.clone(); - match load(load_data, &ui_provider, &http_state, + match load(&load_data, &ui_provider, &http_state, devtools_chan, &factory, user_agent, &cancel_listener) { Err(LoadError::UnsupportedScheme(url)) => { @@ -180,14 +179,14 @@ fn load_for_consumer(load_data: LoadData, let mut image = resources_dir_path(); image.push("badcert.html"); - let load_data = LoadData::new(context, Url::from_file_path(&*image).unwrap(), None); + let load_data = LoadData::new(load_data.context, Url::from_file_path(&*image).unwrap(), None); file_loader::factory(load_data, start_chan, classifier, cancel_listener) } Err(LoadError::ConnectionAborted(_)) => unreachable!(), Ok(mut load_response) => { let metadata = load_response.metadata.clone(); - send_data(context, &mut load_response, start_chan, metadata, classifier, &cancel_listener) + send_data(load_data.context, &mut load_response, start_chan, metadata, classifier, &cancel_listener) } } } @@ -719,14 +718,14 @@ impl UIProvider for TFDProvider { struct TFDProvider; -pub fn load(load_data: LoadData, - ui_provider: &B, - http_state: &HttpState, - devtools_chan: Option>, - request_factory: &HttpRequestFactory, - user_agent: String, - cancel_listener: &CancellationListener) - -> Result, LoadError> where A: HttpRequest + 'static, B: UIProvider { +pub fn load(load_data: &LoadData, + ui_provider: &B, + http_state: &HttpState, + devtools_chan: Option>, + request_factory: &HttpRequestFactory, + user_agent: String, + cancel_listener: &CancellationListener) + -> Result, LoadError> where A: HttpRequest + 'static, B: UIProvider { let max_redirects = prefs::get_pref("network.http.redirection-limit").as_i64().unwrap() as u32; let mut iters = 0; // URL of the document being loaded, as seen by all the higher-level code. diff --git a/tests/unit/net/http_loader.rs b/tests/unit/net/http_loader.rs index 1a035c075e7..3b9da166a45 100644 --- a/tests/unit/net/http_loader.rs +++ b/tests/unit/net/http_loader.rs @@ -346,7 +346,7 @@ fn test_check_default_headers_loaded_in_every_request() { headers.set(UserAgent(DEFAULT_USER_AGENT.to_owned())); // Testing for method.GET - let _ = load(load_data.clone(), &ui_provider, &http_state, None, + let _ = load(&load_data, &ui_provider, &http_state, None, &AssertMustHaveHeadersRequestFactory { expected_headers: headers.clone(), body: <[_]>::to_vec(&[]) @@ -357,7 +357,7 @@ fn test_check_default_headers_loaded_in_every_request() { headers.set(ContentLength(0 as u64)); - let _ = load(load_data.clone(), &ui_provider, &http_state, None, + let _ = load(&load_data, &ui_provider, &http_state, None, &AssertMustHaveHeadersRequestFactory { expected_headers: headers, body: <[_]>::to_vec(&[]) @@ -379,7 +379,7 @@ fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length content_length.set(ContentLength(0)); let _ = load( - load_data.clone(), &ui_provider, &http_state, + &load_data, &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { expected_headers: content_length, body: <[_]>::to_vec(&[]) @@ -413,7 +413,7 @@ fn test_request_and_response_data_with_network_messages() { let mut request_headers = Headers::new(); request_headers.set(Host { hostname: "bar.foo".to_owned(), port: None }); load_data.headers = request_headers.clone(); - let _ = load(load_data, &ui_provider, &http_state, Some(devtools_chan), &Factory, + let _ = load(&load_data, &ui_provider, &http_state, Some(devtools_chan), &Factory, DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)); // notification received from devtools @@ -483,7 +483,7 @@ fn test_request_and_response_message_from_devtool_without_pipeline_id() { let url = Url::parse("https://mozilla.com").unwrap(); let (devtools_chan, devtools_port) = mpsc::channel::(); let load_data = LoadData::new(LoadContext::Browsing, url.clone(), None); - let _ = load(load_data, &ui_provider, &http_state, Some(devtools_chan), &Factory, + let _ = load(&load_data, &ui_provider, &http_state, Some(devtools_chan), &Factory, DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)); // notification received from devtools @@ -517,7 +517,7 @@ fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - let _ = load(load_data, &ui_provider, &http_state, None, &Factory, + let _ = load(&load_data, &ui_provider, &http_state, None, &Factory, DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)); } @@ -546,7 +546,7 @@ fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_co let ui_provider = TestProvider::new(); let mut response = load( - load_data, &ui_provider, &http_state, None, + &load_data, &ui_provider, &http_state, None, &Factory, DEFAULT_USER_AGENT.to_owned(), &CancellationListener::new(None)) @@ -579,7 +579,7 @@ fn test_load_should_decode_the_response_as_gzip_when_response_headers_have_conte let ui_provider = TestProvider::new(); let mut response = load( - load_data, + &load_data, &ui_provider, &http_state, None, &Factory, DEFAULT_USER_AGENT.to_owned(), @@ -623,7 +623,7 @@ fn test_load_doesnt_send_request_body_on_any_redirect() { let ui_provider = TestProvider::new(); let _ = load( - load_data, &ui_provider, &http_state, + &load_data, &ui_provider, &http_state, None, &Factory, DEFAULT_USER_AGENT.to_owned(), @@ -652,7 +652,7 @@ fn test_load_doesnt_add_host_to_sts_list_when_url_is_http_even_if_sts_headers_ar let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - let _ = load(load_data, + let _ = load(&load_data, &ui_provider, &http_state, None, &Factory, @@ -684,7 +684,7 @@ fn test_load_adds_host_to_sts_list_when_url_is_https_and_sts_headers_are_present let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - let _ = load(load_data, + let _ = load(&load_data, &ui_provider, &http_state, None, &Factory, @@ -718,7 +718,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_ let load_data = LoadData::new(LoadContext::Browsing, url.clone(), None); - let _ = load(load_data, + let _ = load(&load_data, &ui_provider, &http_state, None, &Factory, @@ -752,7 +752,7 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re let mut cookie = Headers::new(); cookie.set(CookieHeader(vec![CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned())])); - let _ = load(load_data.clone(), &ui_provider, &http_state, None, + let _ = load(&load_data.clone(), &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { expected_headers: cookie, body: <[_]>::to_vec(&*load_data.data.unwrap()) @@ -795,7 +795,7 @@ fn test_load_sends_secure_cookie_if_http_changed_to_https_due_to_entry_in_hsts_s headers.set_raw("Cookie".to_owned(), vec![<[_]>::to_vec("mozillaIs=theBest".as_bytes())]); let _ = load( - load_data.clone(), &ui_provider, &http_state, None, + &load_data.clone(), &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { expected_headers: headers, body: <[_]>::to_vec(&*load_data.data.unwrap()) @@ -827,7 +827,7 @@ fn test_load_sends_cookie_if_nonhttp() { headers.set_raw("Cookie".to_owned(), vec![<[_]>::to_vec("mozillaIs=theBest".as_bytes())]); let _ = load( - load_data.clone(), &ui_provider, &http_state, None, + &load_data.clone(), &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { expected_headers: headers, body: <[_]>::to_vec(&*load_data.data.unwrap()) @@ -855,7 +855,7 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl( let ui_provider = TestProvider::new(); let load_data = LoadData::new(LoadContext::Browsing, url.clone(), None); - let _ = load(load_data, + let _ = load(&load_data, &ui_provider, &http_state, None, &Factory, @@ -885,7 +885,7 @@ fn test_when_cookie_received_marked_secure_is_ignored_for_http() { let ui_provider = TestProvider::new(); let load_data = LoadData::new(LoadContext::Browsing, Url::parse("http://mozilla.com").unwrap(), None); - let _ = load(load_data, + let _ = load(&load_data, &ui_provider, &http_state, None, &Factory, @@ -921,7 +921,7 @@ fn test_when_cookie_set_marked_httpsonly_secure_isnt_sent_on_http_request() { assert_cookie_for_domain(http_state.cookie_jar.clone(), "https://mozilla.com", "mozillaIs=theBest"); let _ = load( - load_data.clone(), &ui_provider, &http_state, None, + &load_data.clone(), &ui_provider, &http_state, None, &AssertMustNotIncludeHeadersRequestFactory { headers_not_expected: vec!["Cookie".to_owned()], body: <[_]>::to_vec(&*load_data.data.unwrap()) @@ -942,7 +942,7 @@ fn test_load_sets_content_length_to_length_of_request_body() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - let _ = load(load_data.clone(), &ui_provider, &http_state, + let _ = load(&load_data.clone(), &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { expected_headers: content_len_headers, body: <[_]>::to_vec(&*load_data.data.unwrap()) @@ -965,7 +965,7 @@ fn test_load_uses_explicit_accept_from_headers_in_load_data() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - let _ = load(load_data, + let _ = load(&load_data, &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { @@ -992,7 +992,7 @@ fn test_load_sets_default_accept_to_html_xhtml_xml_and_then_anything_else() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - let _ = load(load_data, + let _ = load(&load_data, &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { @@ -1015,7 +1015,7 @@ fn test_load_uses_explicit_accept_encoding_from_load_data_headers() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - let _ = load(load_data, + let _ = load(&load_data, &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { @@ -1039,7 +1039,7 @@ fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - let _ = load(load_data, + let _ = load(&load_data, &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { @@ -1073,7 +1073,7 @@ fn test_load_errors_when_there_a_redirect_loop() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - 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)) { Err(LoadError::InvalidRedirect(_, msg)) => { assert_eq!(msg, "redirect loop"); @@ -1108,7 +1108,7 @@ fn test_load_errors_when_there_is_too_many_redirects() { 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)) { Err(LoadError::MaxRedirects(url, num_redirects)) => { assert_eq!(num_redirects, redirect_limit as u32); @@ -1150,7 +1150,7 @@ fn test_load_follows_a_redirect() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - 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)) { Err(e) => panic!("expected to follow a redirect {:?}", e), Ok(mut lr) => { @@ -1178,7 +1178,7 @@ fn test_load_errors_when_scheme_is_not_http_or_https() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - match load(load_data, + match load(&load_data, &ui_provider, &http_state, None, &DontConnectFactory, @@ -1197,7 +1197,7 @@ fn test_load_errors_when_viewing_source_and_inner_url_scheme_is_not_http_or_http let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - match load(load_data, + match load(&load_data, &ui_provider, &http_state, None, &DontConnectFactory, @@ -1239,7 +1239,7 @@ fn test_load_errors_when_cancelled() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - match load(load_data, + match load(&load_data, &ui_provider, &http_state, None, &Factory, @@ -1309,7 +1309,7 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() { cookie_jar.push(cookie_y, CookieSource::HTTP); } - match load(load_data, + match load(&load_data, &ui_provider, &http_state, None, &Factory, @@ -1355,7 +1355,7 @@ fn test_redirect_from_x_to_x_provides_x_with_cookie_from_first_response() { let http_state = HttpState::new(); let ui_provider = TestProvider::new(); - match load(load_data, + match load(&load_data, &ui_provider, &http_state, None, &Factory, @@ -1398,7 +1398,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() { ); let _ = load( - load_data.clone(), &ui_provider, &http_state, + &load_data, &ui_provider, &http_state, None, &AssertMustIncludeHeadersRequestFactory { expected_headers: auth_header, body: <[_]>::to_vec(&[]) @@ -1425,7 +1425,7 @@ fn test_auth_ui_sets_header_on_401() { let load_data = LoadData::new(LoadContext::Browsing, url, None); match load( - load_data.clone(), &ui_provider, &http_state, + &load_data, &ui_provider, &http_state, None, &AssertAuthHeaderRequestFactory { expected_headers: auth_header, body: <[_]>::to_vec(&[])