mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
clippy: Fix warnings in components/net
(#31626)
* clippy: fix warnings in `components/net` * fix: review comments
This commit is contained in:
parent
5ea0531775
commit
63527f56ca
8 changed files with 54 additions and 53 deletions
|
@ -192,9 +192,9 @@ impl CookieStorage {
|
|||
(match acc.len() {
|
||||
0 => acc,
|
||||
_ => acc + "; ",
|
||||
}) + &c.cookie.name() +
|
||||
}) + c.cookie.name() +
|
||||
"=" +
|
||||
&c.cookie.value()
|
||||
c.cookie.value()
|
||||
};
|
||||
let result = url_cookies.iter_mut().fold("".to_owned(), reducer);
|
||||
|
||||
|
@ -253,7 +253,7 @@ fn evict_one_cookie(is_secure_cookie: bool, cookies: &mut Vec<Cookie>) -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
fn get_oldest_accessed(is_secure_cookie: bool, cookies: &mut Vec<Cookie>) -> Option<(usize, Tm)> {
|
||||
fn get_oldest_accessed(is_secure_cookie: bool, cookies: &mut [Cookie]) -> Option<(usize, Tm)> {
|
||||
let mut oldest_accessed: Option<(usize, Tm)> = None;
|
||||
for (i, c) in cookies.iter().enumerate() {
|
||||
if (c.cookie.secure().unwrap_or(false) == is_secure_cookie) &&
|
||||
|
|
|
@ -248,7 +248,7 @@ fn poll_with_read(reader: &mut dyn Read, buf: &mut BytesMut) -> Poll<Option<Resu
|
|||
};
|
||||
|
||||
match read {
|
||||
Ok(read) if read == 0 => Poll::Ready(None),
|
||||
Ok(0) => Poll::Ready(None),
|
||||
Ok(read) => {
|
||||
unsafe { buf.advance_mut(read) };
|
||||
let chunk = buf.split_to(read).freeze();
|
||||
|
|
|
@ -440,10 +440,7 @@ pub async fn main_fetch(
|
|||
let not_network_error = !response_is_network_error && !internal_response.is_network_error();
|
||||
if not_network_error &&
|
||||
(is_null_body_status(&internal_response.status) ||
|
||||
match request.method {
|
||||
Method::HEAD | Method::CONNECT => true,
|
||||
_ => false,
|
||||
})
|
||||
matches!(request.method, Method::HEAD | Method::CONNECT))
|
||||
{
|
||||
// when Fetch is used only asynchronously, we will need to make sure
|
||||
// that nothing tries to write to the body at this point
|
||||
|
@ -487,7 +484,7 @@ pub async fn main_fetch(
|
|||
if request.synchronous {
|
||||
// process_response is not supposed to be used
|
||||
// by sync fetch, but we overload it here for simplicity
|
||||
target.process_response(&mut response);
|
||||
target.process_response(&response);
|
||||
if !response_loaded {
|
||||
wait_for_response(&mut response, target, done_chan).await;
|
||||
}
|
||||
|
@ -872,16 +869,13 @@ async fn scheme_fetch(
|
|||
}
|
||||
|
||||
fn is_null_body_status(status: &Option<(StatusCode, String)>) -> bool {
|
||||
match *status {
|
||||
Some((status, _)) => match status {
|
||||
StatusCode::SWITCHING_PROTOCOLS |
|
||||
StatusCode::NO_CONTENT |
|
||||
StatusCode::RESET_CONTENT |
|
||||
StatusCode::NOT_MODIFIED => true,
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
status,
|
||||
Some((StatusCode::SWITCHING_PROTOCOLS, ..)) |
|
||||
Some((StatusCode::NO_CONTENT, ..)) |
|
||||
Some((StatusCode::RESET_CONTENT, ..)) |
|
||||
Some((StatusCode::NOT_MODIFIED, ..))
|
||||
)
|
||||
}
|
||||
|
||||
/// <https://fetch.spec.whatwg.org/#should-response-to-request-be-blocked-due-to-nosniff?>
|
||||
|
|
|
@ -125,6 +125,7 @@ impl FileManager {
|
|||
// Read a file for the Fetch implementation.
|
||||
// It gets the required headers synchronously and reads the actual content
|
||||
// in a separate thread.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn fetch_file(
|
||||
&self,
|
||||
done_sender: &mut TokioSender<Data>,
|
||||
|
@ -278,6 +279,7 @@ impl FileManager {
|
|||
});
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn fetch_blob_buf(
|
||||
&self,
|
||||
done_sender: &mut TokioSender<Data>,
|
||||
|
@ -824,22 +826,20 @@ impl FileManagerStore {
|
|||
}
|
||||
|
||||
fn promote_memory(&self, id: Uuid, blob_buf: BlobBuf, set_valid: bool, origin: FileOrigin) {
|
||||
match Url::parse(&origin) {
|
||||
// parse to check sanity
|
||||
Ok(_) => {
|
||||
self.insert(
|
||||
id,
|
||||
FileStoreEntry {
|
||||
origin,
|
||||
file_impl: FileImpl::Memory(blob_buf),
|
||||
refs: AtomicUsize::new(1),
|
||||
is_valid_url: AtomicBool::new(set_valid),
|
||||
outstanding_tokens: Default::default(),
|
||||
},
|
||||
);
|
||||
},
|
||||
Err(_) => {},
|
||||
// parse to check sanity
|
||||
if Url::parse(&origin).is_err() {
|
||||
return;
|
||||
}
|
||||
self.insert(
|
||||
id,
|
||||
FileStoreEntry {
|
||||
origin,
|
||||
file_impl: FileImpl::Memory(blob_buf),
|
||||
refs: AtomicUsize::new(1),
|
||||
is_valid_url: AtomicBool::new(set_valid),
|
||||
outstanding_tokens: Default::default(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn set_blob_url_validity(
|
||||
|
|
|
@ -134,10 +134,10 @@ pub struct HttpCache {
|
|||
|
||||
/// Determine if a response is cacheable by default <https://tools.ietf.org/html/rfc7231#section-6.1>
|
||||
fn is_cacheable_by_default(status_code: u16) -> bool {
|
||||
match status_code {
|
||||
200 | 203 | 204 | 206 | 300 | 301 | 404 | 405 | 410 | 414 | 501 => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
status_code,
|
||||
200 | 203 | 204 | 206 | 300 | 301 | 404 | 405 | 410 | 414 | 501
|
||||
)
|
||||
}
|
||||
|
||||
/// Determine if a given response is cacheable.
|
||||
|
|
|
@ -85,6 +85,8 @@ pub enum HttpCacheEntryState {
|
|||
PendingStore(usize),
|
||||
}
|
||||
|
||||
type HttpCacheState = Mutex<HashMap<CacheKey, Arc<(Mutex<HttpCacheEntryState>, Condvar)>>>;
|
||||
|
||||
pub struct HttpState {
|
||||
pub hsts_list: RwLock<HstsList>,
|
||||
pub cookie_jar: RwLock<CookieStorage>,
|
||||
|
@ -92,7 +94,7 @@ pub struct HttpState {
|
|||
/// A map of cache key to entry state,
|
||||
/// reflecting whether the cache entry is ready to read from,
|
||||
/// or whether a concurrent pending store should be awaited.
|
||||
pub http_cache_state: Mutex<HashMap<CacheKey, Arc<(Mutex<HttpCacheEntryState>, Condvar)>>>,
|
||||
pub http_cache_state: HttpCacheState,
|
||||
pub auth_cache: RwLock<AuthCache>,
|
||||
pub history_states: RwLock<HashMap<HistoryStateId, Vec<u8>>>,
|
||||
pub client: Client<Connector, Body>,
|
||||
|
@ -348,6 +350,7 @@ fn set_cookies_from_headers(
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn prepare_devtools_request(
|
||||
request_id: String,
|
||||
url: ServoUrl,
|
||||
|
@ -478,6 +481,7 @@ impl BodySink {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn obtain_response(
|
||||
client: &Client<Connector, Body>,
|
||||
url: &ServoUrl,
|
||||
|
@ -703,6 +707,7 @@ async fn obtain_response(
|
|||
|
||||
/// [HTTP fetch](https://fetch.spec.whatwg.org#http-fetch)
|
||||
#[async_recursion]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn http_fetch(
|
||||
request: &mut Request,
|
||||
cache: &mut CorsCache,
|
||||
|
@ -2077,6 +2082,7 @@ async fn cors_preflight_fetch(
|
|||
|
||||
// Substep 7
|
||||
let unsafe_names = get_cors_unsafe_header_names(&request.headers);
|
||||
#[allow(clippy::mutable_key_type)] // We don't mutate the items in the set
|
||||
let header_names_set: HashSet<&HeaderName> = HashSet::from_iter(header_names.iter());
|
||||
let header_names_contains_star = header_names.iter().any(|hn| hn.as_str() == "*");
|
||||
for unsafe_name in unsafe_names.iter() {
|
||||
|
@ -2180,12 +2186,12 @@ fn is_no_store_cache(headers: &HeaderMap) -> bool {
|
|||
|
||||
/// <https://fetch.spec.whatwg.org/#redirect-status>
|
||||
pub fn is_redirect_status(status: &(StatusCode, String)) -> bool {
|
||||
match status.0 {
|
||||
matches!(
|
||||
status.0,
|
||||
StatusCode::MOVED_PERMANENTLY |
|
||||
StatusCode::FOUND |
|
||||
StatusCode::SEE_OTHER |
|
||||
StatusCode::TEMPORARY_REDIRECT |
|
||||
StatusCode::PERMANENT_REDIRECT => true,
|
||||
_ => false,
|
||||
}
|
||||
StatusCode::FOUND |
|
||||
StatusCode::SEE_OTHER |
|
||||
StatusCode::TEMPORARY_REDIRECT |
|
||||
StatusCode::PERMANENT_REDIRECT
|
||||
)
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ fn load_root_cert_store_from_file(file_path: String) -> io::Result<RootCertStore
|
|||
}
|
||||
|
||||
/// Returns a tuple of (public, private) senders to the new threads.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new_resource_threads(
|
||||
user_agent: Cow<'static, str>,
|
||||
devtools_sender: Option<Sender<DevtoolsControlMsg>>,
|
||||
|
@ -102,6 +103,7 @@ pub fn new_resource_threads(
|
|||
}
|
||||
|
||||
/// Create a CoreResourceThread
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new_core_resource_thread(
|
||||
user_agent: Cow<'static, str>,
|
||||
devtools_sender: Option<Sender<DevtoolsControlMsg>>,
|
||||
|
@ -225,9 +227,8 @@ impl ResourceChannelManager {
|
|||
loop {
|
||||
for receiver in rx_set.select().unwrap().into_iter() {
|
||||
// Handles case where profiler thread shuts down before resource thread.
|
||||
match receiver {
|
||||
ipc::IpcSelectionResult::ChannelClosed(..) => continue,
|
||||
_ => {},
|
||||
if let ipc::IpcSelectionResult::ChannelClosed(..) = receiver {
|
||||
continue;
|
||||
}
|
||||
let (id, data) = receiver.unwrap();
|
||||
// If message is memory report, get the size_of of public and private http caches
|
||||
|
|
|
@ -132,10 +132,10 @@ fn apply_algorithm_to_response<S: ArrayLength<u8>, D: Digest<OutputSize = S>>(
|
|||
|
||||
/// <https://w3c.github.io/webappsec-subresource-integrity/#is-response-eligible>
|
||||
fn is_eligible_for_integrity_validation(response: &Response) -> bool {
|
||||
match response.response_type {
|
||||
ResponseType::Basic | ResponseType::Default | ResponseType::Cors => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
response.response_type,
|
||||
ResponseType::Basic | ResponseType::Default | ResponseType::Cors
|
||||
)
|
||||
}
|
||||
|
||||
/// <https://w3c.github.io/webappsec-subresource-integrity/#does-response-match-metadatalist>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue