mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
clippy: fix warnings in components/net (#31564)
* clippy: fix some warnings in components/net * fix: review comments * fix: tidy
This commit is contained in:
parent
099bb0fa19
commit
67b277c992
22 changed files with 325 additions and 379 deletions
|
@ -60,11 +60,11 @@ impl CorsCacheEntry {
|
|||
header_or_method: HeaderOrMethod,
|
||||
) -> CorsCacheEntry {
|
||||
CorsCacheEntry {
|
||||
origin: origin,
|
||||
url: url,
|
||||
max_age: max_age,
|
||||
credentials: credentials,
|
||||
header_or_method: header_or_method,
|
||||
origin,
|
||||
url,
|
||||
max_age,
|
||||
credentials,
|
||||
header_or_method,
|
||||
created: time::now().to_timespec(),
|
||||
}
|
||||
}
|
||||
|
@ -77,14 +77,10 @@ fn match_headers(cors_cache: &CorsCacheEntry, cors_req: &Request) -> bool {
|
|||
}
|
||||
|
||||
/// A simple, vector-based CORS Cache
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct CorsCache(Vec<CorsCacheEntry>);
|
||||
|
||||
impl CorsCache {
|
||||
pub fn new() -> CorsCache {
|
||||
CorsCache(vec![])
|
||||
}
|
||||
|
||||
fn find_entry_by_header<'a>(
|
||||
&'a mut self,
|
||||
request: &Request,
|
||||
|
@ -122,7 +118,7 @@ impl CorsCache {
|
|||
/// Returns true if an entry with a
|
||||
/// [matching header](https://fetch.spec.whatwg.org/#concept-cache-match-header) is found
|
||||
pub fn match_header(&mut self, request: &Request, header_name: &HeaderName) -> bool {
|
||||
self.find_entry_by_header(&request, header_name).is_some()
|
||||
self.find_entry_by_header(request, header_name).is_some()
|
||||
}
|
||||
|
||||
/// Updates max age if an entry for a
|
||||
|
@ -136,7 +132,7 @@ impl CorsCache {
|
|||
new_max_age: u32,
|
||||
) -> bool {
|
||||
match self
|
||||
.find_entry_by_header(&request, header_name)
|
||||
.find_entry_by_header(request, header_name)
|
||||
.map(|e| e.max_age = new_max_age)
|
||||
{
|
||||
Some(_) => true,
|
||||
|
@ -156,7 +152,7 @@ impl CorsCache {
|
|||
/// Returns true if an entry with a
|
||||
/// [matching method](https://fetch.spec.whatwg.org/#concept-cache-match-method) is found
|
||||
pub fn match_method(&mut self, request: &Request, method: Method) -> bool {
|
||||
self.find_entry_by_method(&request, method).is_some()
|
||||
self.find_entry_by_method(request, method).is_some()
|
||||
}
|
||||
|
||||
/// Updates max age if an entry for
|
||||
|
@ -170,7 +166,7 @@ impl CorsCache {
|
|||
new_max_age: u32,
|
||||
) -> bool {
|
||||
match self
|
||||
.find_entry_by_method(&request, method.clone())
|
||||
.find_entry_by_method(request, method.clone())
|
||||
.map(|e| e.max_age = new_max_age)
|
||||
{
|
||||
Some(_) => true,
|
||||
|
|
|
@ -17,14 +17,14 @@ pub fn determine_nosniff(headers: &HeaderMap) -> bool {
|
|||
|
||||
match values {
|
||||
None => false,
|
||||
Some(values) => !values.is_empty() && (&values[0]).eq_ignore_ascii_case("nosniff"),
|
||||
Some(values) => !values.is_empty() && values[0].eq_ignore_ascii_case("nosniff"),
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://fetch.spec.whatwg.org/#concept-header-list-get-decode-split>
|
||||
fn get_header_value_as_list(name: &str, headers: &HeaderMap) -> Option<Vec<String>> {
|
||||
fn char_is_not_quote_or_comma(c: char) -> bool {
|
||||
return c != '\u{0022}' && c != '\u{002C}';
|
||||
c != '\u{0022}' && c != '\u{002C}'
|
||||
}
|
||||
|
||||
// Step 1
|
||||
|
@ -33,7 +33,7 @@ fn get_header_value_as_list(name: &str, headers: &HeaderMap) -> Option<Vec<Strin
|
|||
if let Some(input) = initial_value {
|
||||
// https://fetch.spec.whatwg.org/#header-value-get-decode-and-split
|
||||
// Step 1
|
||||
let input = input.into_iter().map(|u| char::from(u)).collect::<String>();
|
||||
let input = input.into_iter().map(char::from).collect::<String>();
|
||||
|
||||
// Step 2
|
||||
let mut position = input.chars().peekable();
|
||||
|
@ -81,7 +81,7 @@ fn get_header_value_as_list(name: &str, headers: &HeaderMap) -> Option<Vec<Strin
|
|||
}
|
||||
|
||||
// Step 2
|
||||
return None;
|
||||
None
|
||||
}
|
||||
|
||||
/// <https://infra.spec.whatwg.org/#collect-a-sequence-of-code-points>
|
||||
|
@ -102,13 +102,13 @@ where
|
|||
}
|
||||
|
||||
// Step 3
|
||||
return result;
|
||||
result
|
||||
}
|
||||
|
||||
/// <https://fetch.spec.whatwg.org/#collect-an-http-quoted-string>
|
||||
fn collect_http_quoted_string(position: &mut Peekable<Chars>, extract_value: bool) -> String {
|
||||
fn char_is_not_quote_or_backslash(c: char) -> bool {
|
||||
return c != '\u{0022}' && c != '\u{005C}';
|
||||
c != '\u{0022}' && c != '\u{005C}'
|
||||
}
|
||||
|
||||
// Step 2
|
||||
|
@ -159,5 +159,5 @@ fn collect_http_quoted_string(position: &mut Peekable<Chars>, extract_value: boo
|
|||
}
|
||||
|
||||
// Step 6, 7
|
||||
return value;
|
||||
value
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ pub struct CancellationListener {
|
|||
impl CancellationListener {
|
||||
pub fn new(cancel_chan: Option<IpcReceiver<()>>) -> Self {
|
||||
Self {
|
||||
cancel_chan: cancel_chan,
|
||||
cancel_chan,
|
||||
cancelled: false,
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ pub async fn fetch(request: &mut Request, target: Target<'_>, context: &FetchCon
|
|||
.unwrap()
|
||||
.set_attribute(ResourceAttribute::StartTime(ResourceTimeValue::FetchStart));
|
||||
|
||||
fetch_with_cors_cache(request, &mut CorsCache::new(), target, context).await;
|
||||
fetch_with_cors_cache(request, &mut CorsCache::default(), target, context).await;
|
||||
}
|
||||
|
||||
pub async fn fetch_with_cors_cache(
|
||||
|
@ -161,7 +161,7 @@ pub async fn fetch_with_cors_cache(
|
|||
}
|
||||
|
||||
// Step 8.
|
||||
main_fetch(request, cache, false, false, target, &mut None, &context).await;
|
||||
main_fetch(request, cache, false, false, target, &mut None, context).await;
|
||||
}
|
||||
|
||||
/// <https://www.w3.org/TR/CSP/#should-block-request>
|
||||
|
@ -209,15 +209,15 @@ pub async fn main_fetch(
|
|||
}
|
||||
|
||||
// Step 2.
|
||||
if request.local_urls_only {
|
||||
if !matches!(
|
||||
if request.local_urls_only &&
|
||||
!matches!(
|
||||
request.current_url().scheme(),
|
||||
"about" | "blob" | "data" | "filesystem"
|
||||
) {
|
||||
response = Some(Response::network_error(NetworkError::Internal(
|
||||
"Non-local scheme".into(),
|
||||
)));
|
||||
}
|
||||
)
|
||||
{
|
||||
response = Some(Response::network_error(NetworkError::Internal(
|
||||
"Non-local scheme".into(),
|
||||
)));
|
||||
}
|
||||
|
||||
// Step 2.2.
|
||||
|
@ -267,7 +267,7 @@ pub async fn main_fetch(
|
|||
)
|
||||
},
|
||||
};
|
||||
request.referrer = referrer_url.map_or(Referrer::NoReferrer, |url| Referrer::ReferrerUrl(url));
|
||||
request.referrer = referrer_url.map_or(Referrer::NoReferrer, Referrer::ReferrerUrl);
|
||||
|
||||
// Step 9.
|
||||
// TODO: handle FTP URLs.
|
||||
|
@ -451,7 +451,7 @@ pub async fn main_fetch(
|
|||
*body = ResponseBody::Empty;
|
||||
}
|
||||
|
||||
internal_response.get_network_error().map(|e| e.clone())
|
||||
internal_response.get_network_error().cloned()
|
||||
};
|
||||
|
||||
// Execute deferred rebinding of response.
|
||||
|
@ -469,7 +469,7 @@ pub async fn main_fetch(
|
|||
response_loaded = true;
|
||||
|
||||
// Step 19.2.
|
||||
let ref integrity_metadata = &request.integrity_metadata;
|
||||
let integrity_metadata = &request.integrity_metadata;
|
||||
if response.termination_reason.is_none() &&
|
||||
!is_response_integrity_valid(integrity_metadata, &response)
|
||||
{
|
||||
|
@ -502,8 +502,8 @@ pub async fn main_fetch(
|
|||
// in http_network_fetch. However, we can't yet follow the request
|
||||
// upload progress, so I'm keeping it here for now and pretending
|
||||
// the body got sent in one chunk
|
||||
target.process_request_body(&request);
|
||||
target.process_request_eof(&request);
|
||||
target.process_request_body(request);
|
||||
target.process_request_eof(request);
|
||||
}
|
||||
|
||||
// Step 22.
|
||||
|
@ -518,7 +518,7 @@ pub async fn main_fetch(
|
|||
target.process_response_eof(&response);
|
||||
|
||||
if let Ok(http_cache) = context.state.http_cache.write() {
|
||||
http_cache.update_awaiting_consumers(&request, &response);
|
||||
http_cache.update_awaiting_consumers(request, &response);
|
||||
}
|
||||
|
||||
// Steps 25-27.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue