From 3e3053653ec7e151f34e8c3b56d2a79ffca91e09 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 9 Mar 2016 15:50:29 +0100 Subject: [PATCH] Fix warnings in the fetch code. --- components/net/fetch/methods.rs | 56 ++++++++++----------------------- components/net/lib.rs | 1 - 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index 6cd19bef12c..b4620aec0f4 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -3,30 +3,24 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use fetch::cors_cache::{BasicCORSCache, CORSCache, CacheRequestDetails}; -use http_loader::{NetworkHttpRequestFactory, WrappedHttpResponse}; -use http_loader::{create_http_connector, obtain_response, read_block, ReadResult}; -use hyper::client::response::Response as HyperResponse; +use http_loader::{NetworkHttpRequestFactory, create_http_connector, obtain_response}; use hyper::header::{Accept, CacheControl, IfMatch, IfRange, IfUnmodifiedSince, Location}; use hyper::header::{AcceptLanguage, ContentLength, ContentLanguage, HeaderView, Pragma}; use hyper::header::{AccessControlAllowCredentials, AccessControlAllowOrigin}; use hyper::header::{Authorization, Basic, CacheDirective, ContentEncoding, Encoding}; -use hyper::header::{ContentType, Header, Headers, IfModifiedSince, IfNoneMatch}; +use hyper::header::{ContentType, Headers, IfModifiedSince, IfNoneMatch}; use hyper::header::{QualityItem, q, qitem, Referer as RefererHeader, UserAgent}; use hyper::method::Method; use hyper::mime::{Attr, Mime, SubLevel, TopLevel, Value}; use hyper::status::StatusCode; +use net_traits::AsyncFetchListener; use net_traits::request::{CacheMode, CredentialsMode, Type, Origin, Window}; use net_traits::request::{RedirectMode, Referer, Request, RequestMode, ResponseTainting}; -use net_traits::response::{CacheState, HttpsState, TerminationReason}; +use net_traits::response::{HttpsState, TerminationReason}; use net_traits::response::{Response, ResponseBody, ResponseType}; -use net_traits::{AsyncFetchListener, Metadata}; use resource_thread::CancellationListener; -use std::ascii::AsciiExt; -use std::cell::RefCell; use std::io::Read; use std::rc::Rc; -use std::str::FromStr; -use std::sync::{Arc, Mutex}; use std::thread; use url::idna::domain_to_ascii; use url::{Origin as UrlOrigin, OpaqueOrigin, Url, UrlParser, whatwg_scheme_type_mapper}; @@ -144,7 +138,7 @@ fn main_fetch(request: Rc, cors_flag: bool, recursive_flag: bool) -> Re // this step is obsoleted by fetch_async // Step 9 - let mut response = if response.is_none() { + let response = if response.is_none() { let current_url = request.current_url(); let same_origin = if let Origin::Origin(ref origin) = *request.origin.borrow() { @@ -198,7 +192,7 @@ fn main_fetch(request: Rc, cors_flag: bool, recursive_flag: bool) -> Re // Step 11 // no need to check if response is a network error, since the type would not be `Default` - let mut response = if response.response_type == ResponseType::Default { + let response = if response.response_type == ResponseType::Default { let response_type = match request.response_tainting.get() { ResponseTainting::Basic => ResponseType::Basic, ResponseTainting::CORSTainting => ResponseType::CORS, @@ -212,7 +206,7 @@ fn main_fetch(request: Rc, cors_flag: bool, recursive_flag: bool) -> Re { // Step 12 let network_error_res = Response::network_error(); - let mut internal_response = if response.is_network_error() { + let internal_response = if response.is_network_error() { &network_error_res } else { response.get_actual_response() @@ -265,7 +259,7 @@ fn main_fetch(request: Rc, cors_flag: bool, recursive_flag: bool) -> Re { // Step 12 repeated to use internal_response let network_error_res = Response::network_error(); - let mut internal_response = if response.is_network_error() { + let internal_response = if response.is_network_error() { &network_error_res } else { response.get_actual_response() @@ -319,21 +313,6 @@ fn basic_fetch(request: Rc) -> Response { } } -fn http_fetch_async(request: Request, - cors_flag: bool, - cors_preflight_flag: bool, - authentication_fetch_flag: bool, - listener: Box) { - - spawn_named(format!("http_fetch for {:?}", request.current_url_string()), move || { - let request = Rc::new(request); - let res = http_fetch(request, BasicCORSCache::new(), - cors_flag, cors_preflight_flag, - authentication_fetch_flag); - listener.response_available(res); - }); -} - /// [HTTP fetch](https://fetch.spec.whatwg.org#http-fetch) fn http_fetch(request: Rc, mut cache: BasicCORSCache, @@ -385,9 +364,6 @@ fn http_fetch(request: Rc, // Substep 1 if cors_preflight_flag { - let mut method_mismatch = false; - let mut header_mismatch = false; - let origin = request.origin.borrow().clone(); let url = request.current_url(); let credentials = request.credentials_mode == CredentialsMode::Include; @@ -397,9 +373,9 @@ fn http_fetch(request: Rc, credentials: credentials }, request.method.borrow().clone()); - method_mismatch = !method_cache_match && (!is_simple_method(&request.method.borrow()) || + let method_mismatch = !method_cache_match && (!is_simple_method(&request.method.borrow()) || request.use_cors_preflight); - header_mismatch = request.headers.borrow().iter().any(|view| + let header_mismatch = request.headers.borrow().iter().any(|view| !cache.match_header(CacheRequestDetails { origin: origin.clone(), destination: url.clone(), @@ -808,8 +784,8 @@ fn http_network_or_cache_fetch(request: Rc, /// [HTTP network fetch](https://fetch.spec.whatwg.org/#http-network-fetch) fn http_network_fetch(request: Rc, - http_request: Rc, - credentials_flag: bool) -> Response { + _http_request: Rc, + _credentials_flag: bool) -> Response { // TODO: Implement HTTP network fetch spec // Step 1 @@ -846,7 +822,7 @@ fn http_network_fetch(request: Rc, *res_body.lock().unwrap() = ResponseBody::Receiving(vec![]); let mut new_body = vec![]; - res.response.read_to_end(&mut new_body); + res.response.read_to_end(&mut new_body).unwrap(); let mut body = res_body.lock().unwrap(); assert!(*body != ResponseBody::Empty); @@ -875,7 +851,7 @@ fn http_network_fetch(request: Rc, // } }); }, - Err(e) => + Err(_) => response.termination_reason = Some(TerminationReason::Fatal) }; @@ -933,7 +909,7 @@ fn http_network_fetch(request: Rc, } /// [CORS preflight fetch](https://fetch.spec.whatwg.org#cors-preflight-fetch) -fn preflight_fetch(request: Rc) -> Response { +fn preflight_fetch(_request: Rc) -> Response { // TODO: Implement preflight fetch spec Response::network_error() } @@ -1071,7 +1047,7 @@ fn includes_credentials(url: &Url) -> bool { false } -fn response_needs_revalidation(response: &Response) -> bool { +fn response_needs_revalidation(_response: &Response) -> bool { // TODO this function false } diff --git a/components/net/lib.rs b/components/net/lib.rs index 6ef801ca7b7..23ac7f832b8 100644 --- a/components/net/lib.rs +++ b/components/net/lib.rs @@ -46,7 +46,6 @@ pub mod websocket_loader; /// An implementation of the [Fetch spec](https://fetch.spec.whatwg.org/) pub mod fetch { - #![allow(dead_code, unused)] // XXXManishearth this is only temporary until the Fetch mod starts being used pub mod cors_cache; pub mod methods; }