Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy: Fix warnings in components/net #31626

Merged
merged 2 commits into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/net/cookie_storage.rs
Expand Up @@ -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);

Expand Down Expand Up @@ -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) &&
Expand Down
2 changes: 1 addition & 1 deletion components/net/decoder.rs
Expand Up @@ -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();
Expand Down
24 changes: 9 additions & 15 deletions components/net/fetch/methods.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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?>
Expand Down
30 changes: 15 additions & 15 deletions components/net/filemanager_thread.rs
Expand Up @@ -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>,
Expand Down Expand Up @@ -278,6 +279,7 @@ impl FileManager {
});
}

#[allow(clippy::too_many_arguments)]
fn fetch_blob_buf(
&self,
done_sender: &mut TokioSender<Data>,
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions components/net/http_cache.rs
Expand Up @@ -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.
Expand Down
22 changes: 14 additions & 8 deletions components/net/http_loader.rs
Expand Up @@ -85,14 +85,16 @@ 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>,
pub http_cache: RwLock<HttpCache>,
/// 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>,
Expand Down Expand Up @@ -348,6 +350,7 @@ fn set_cookies_from_headers(
}
}

#[allow(clippy::too_many_arguments)]
fn prepare_devtools_request(
request_id: String,
url: ServoUrl,
Expand Down Expand Up @@ -478,6 +481,7 @@ impl BodySink {
}
}

#[allow(clippy::too_many_arguments)]
async fn obtain_response(
client: &Client<Connector, Body>,
url: &ServoUrl,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
)
}
7 changes: 4 additions & 3 deletions components/net/resource_thread.rs
Expand Up @@ -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>>,
Expand Down Expand Up @@ -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>>,
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions components/net/subresource_integrity.rs
Expand Up @@ -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>
Expand Down