1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-23 16:21:06 +01:00

chore: address clippy warnings

This commit is contained in:
Rob Ede 2023-07-20 11:02:15 +01:00
parent 1040bc3d17
commit 3eb5a059ad
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
22 changed files with 87 additions and 92 deletions

View File

@ -12,7 +12,7 @@ pub use self::{decoder::Decoder, encoder::Encoder};
/// Special-purpose writer for streaming (de-)compression.
///
/// Pre-allocates 8KiB of capacity.
pub(self) struct Writer {
struct Writer {
buf: BytesMut,
}

View File

@ -50,7 +50,7 @@ mod tests {
#[test]
fn test_apply_mask() {
let mask = [0x6d, 0xb6, 0xb2, 0x80];
let unmasked = vec![
let unmasked = [
0xf3, 0x00, 0x01, 0x02, 0x03, 0x80, 0x81, 0x82, 0xff, 0xfe, 0x00, 0x17, 0x74, 0xf9,
0x12, 0x03,
];

View File

@ -1,5 +1,3 @@
#![allow(clippy::uninlined_format_args)]
use std::{
convert::Infallible,
io::{Read, Write},
@ -139,7 +137,7 @@ async fn expect_continue_h1() {
#[actix_rt::test]
async fn chunked_payload() {
let chunk_sizes = vec![32768, 32, 32768];
let chunk_sizes = [32768, 32, 32768];
let total_size: usize = chunk_sizes.iter().sum();
let mut srv = test_server(|| {
@ -402,7 +400,7 @@ async fn content_length() {
let mut srv = test_server(|| {
HttpService::build()
.h1(|req: Request| {
let indx: usize = req.uri().path()[1..].parse().unwrap();
let idx: usize = req.uri().path()[1..].parse().unwrap();
let statuses = [
StatusCode::NO_CONTENT,
StatusCode::CONTINUE,
@ -411,7 +409,7 @@ async fn content_length() {
StatusCode::OK,
StatusCode::NOT_FOUND,
];
ok::<_, Infallible>(Response::new(statuses[indx]))
ok::<_, Infallible>(Response::new(statuses[idx]))
})
.tcp()
})

View File

@ -1529,7 +1529,12 @@ mod tests {
assert!(!resource.resource_path_from_iter(&mut s, &mut ["item"].iter()));
let mut s = String::new();
assert!(resource.resource_path_from_iter(&mut s, &mut vec!["item", "item2"].iter()));
assert!(resource.resource_path_from_iter(
&mut s,
#[allow(clippy::useless_vec)]
&mut vec!["item", "item2"].iter()
));
assert_eq!(s, "/user/item/item2/");
}

View File

@ -78,7 +78,7 @@ common_header! {
// Tests from the RFC
crate::http::header::common_header_test!(
test1,
vec![b"audio/*; q=0.2, audio/basic"],
[b"audio/*; q=0.2, audio/basic"],
Some(Accept(vec![
QualityItem::new("audio/*".parse().unwrap(), q(0.2)),
QualityItem::max("audio/basic".parse().unwrap()),
@ -86,7 +86,7 @@ common_header! {
crate::http::header::common_header_test!(
test2,
vec![b"text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"],
[b"text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c"],
Some(Accept(vec![
QualityItem::new(mime::TEXT_PLAIN, q(0.5)),
QualityItem::max(mime::TEXT_HTML),
@ -99,13 +99,13 @@ common_header! {
// Custom tests
crate::http::header::common_header_test!(
test3,
vec![b"text/plain; charset=utf-8"],
[b"text/plain; charset=utf-8"],
Some(Accept(vec![
QualityItem::max(mime::TEXT_PLAIN_UTF_8),
])));
crate::http::header::common_header_test!(
test4,
vec![b"text/plain; charset=utf-8; q=0.5"],
[b"text/plain; charset=utf-8; q=0.5"],
Some(Accept(vec![
QualityItem::new(mime::TEXT_PLAIN_UTF_8, q(0.5)),
])));

View File

@ -57,6 +57,6 @@ common_header! {
test_parse_and_format {
// Test case from RFC
common_header_test!(test1, vec![b"iso-8859-5, unicode-1-1;q=0.8"]);
common_header_test!(test1, [b"iso-8859-5, unicode-1-1;q=0.8"]);
}
}

View File

@ -50,31 +50,31 @@ common_header! {
(AcceptEncoding, header::ACCEPT_ENCODING) => (QualityItem<Preference<Encoding>>)*
test_parse_and_format {
common_header_test!(no_headers, vec![b""; 0], Some(AcceptEncoding(vec![])));
common_header_test!(empty_header, vec![b""; 1], Some(AcceptEncoding(vec![])));
common_header_test!(no_headers, [b""; 0], Some(AcceptEncoding(vec![])));
common_header_test!(empty_header, [b""; 1], Some(AcceptEncoding(vec![])));
common_header_test!(
order_of_appearance,
vec![b"br, gzip"],
[b"br, gzip"],
Some(AcceptEncoding(vec![
QualityItem::max(Preference::Specific(Encoding::brotli())),
QualityItem::max(Preference::Specific(Encoding::gzip())),
]))
);
common_header_test!(any, vec![b"*"], Some(AcceptEncoding(vec![
common_header_test!(any, [b"*"], Some(AcceptEncoding(vec![
QualityItem::max(Preference::Any),
])));
// Note: Removed quality 1 from gzip
common_header_test!(implicit_quality, vec![b"gzip, identity; q=0.5, *;q=0"]);
common_header_test!(implicit_quality, [b"gzip, identity; q=0.5, *;q=0"]);
// Note: Removed quality 1 from gzip
common_header_test!(implicit_quality_out_of_order, vec![b"compress;q=0.5, gzip"]);
common_header_test!(implicit_quality_out_of_order, [b"compress;q=0.5, gzip"]);
common_header_test!(
only_gzip_no_identity,
vec![b"gzip, *; q=0"],
[b"gzip, *; q=0"],
Some(AcceptEncoding(vec![
QualityItem::max(Preference::Specific(Encoding::gzip())),
QualityItem::zero(Preference::Any),

View File

@ -58,19 +58,19 @@ common_header! {
(AcceptLanguage, header::ACCEPT_LANGUAGE) => (QualityItem<Preference<LanguageTag>>)*
test_parse_and_format {
common_header_test!(no_headers, vec![b""; 0], Some(AcceptLanguage(vec![])));
common_header_test!(no_headers, [b""; 0], Some(AcceptLanguage(vec![])));
common_header_test!(empty_header, vec![b""; 1], Some(AcceptLanguage(vec![])));
common_header_test!(empty_header, [b""; 1], Some(AcceptLanguage(vec![])));
common_header_test!(
example_from_rfc,
vec![b"da, en-gb;q=0.8, en;q=0.7"]
[b"da, en-gb;q=0.8, en;q=0.7"]
);
common_header_test!(
not_ordered_by_weight,
vec![b"en-US, en; q=0.5, fr"],
[b"en-US, en; q=0.5, fr"],
Some(AcceptLanguage(vec![
QualityItem::max("en-US".parse().unwrap()),
QualityItem::new("en".parse().unwrap(), q(0.5)),
@ -80,7 +80,7 @@ common_header! {
common_header_test!(
has_wildcard,
vec![b"fr-CH, fr; q=0.9, en; q=0.8, de; q=0.7, *; q=0.5"],
[b"fr-CH, fr; q=0.9, en; q=0.8, de; q=0.7, *; q=0.5"],
Some(AcceptLanguage(vec![
QualityItem::max("fr-CH".parse().unwrap()),
QualityItem::new("fr".parse().unwrap(), q(0.9)),
@ -137,7 +137,7 @@ impl AcceptLanguage {
b.quality.cmp(&a.quality)
});
types.into_iter().map(|qitem| qitem.item).collect()
types.into_iter().map(|q_item| q_item.item).collect()
}
}

View File

@ -51,12 +51,12 @@ crate::http::header::common_header! {
// From the RFC
crate::http::header::common_header_test!(
test1,
vec![b"GET, HEAD, PUT"],
[b"GET, HEAD, PUT"],
Some(HeaderField(vec![Method::GET, Method::HEAD, Method::PUT])));
// Own tests
crate::http::header::common_header_test!(
test2,
vec![b"OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH"],
[b"OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH"],
Some(HeaderField(vec![
Method::OPTIONS,
Method::GET,
@ -69,7 +69,7 @@ crate::http::header::common_header! {
Method::PATCH])));
crate::http::header::common_header_test!(
test3,
vec![b""],
[b""],
Some(HeaderField(Vec::<Method>::new())));
}
}

View File

@ -47,13 +47,13 @@ common_header! {
(CacheControl, header::CACHE_CONTROL) => (CacheDirective)+
test_parse_and_format {
common_header_test!(no_headers, vec![b""; 0], None);
common_header_test!(empty_header, vec![b""; 1], None);
common_header_test!(bad_syntax, vec![b"foo="], None);
common_header_test!(no_headers, [b""; 0], None);
common_header_test!(empty_header, [b""; 1], None);
common_header_test!(bad_syntax, [b"foo="], None);
common_header_test!(
multiple_headers,
vec![&b"no-cache"[..], &b"private"[..]],
[&b"no-cache"[..], &b"private"[..]],
Some(CacheControl(vec![
CacheDirective::NoCache,
CacheDirective::Private,
@ -62,7 +62,7 @@ common_header! {
common_header_test!(
argument,
vec![b"max-age=100, private"],
[b"max-age=100, private"],
Some(CacheControl(vec![
CacheDirective::MaxAge(100),
CacheDirective::Private,
@ -71,7 +71,7 @@ common_header! {
common_header_test!(
extension,
vec![b"foo, bar=baz"],
[b"foo, bar=baz"],
Some(CacheControl(vec![
CacheDirective::Extension("foo".to_owned(), None),
CacheDirective::Extension("bar".to_owned(), Some("baz".to_owned())),

View File

@ -48,7 +48,7 @@ common_header! {
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+
test_parse_and_format {
crate::http::header::common_header_test!(test1, vec![b"da"]);
crate::http::header::common_header_test!(test2, vec![b"mi, en"]);
crate::http::header::common_header_test!(test1, [b"da"]);
crate::http::header::common_header_test!(test2, [b"mi, en"]);
}
}

View File

@ -13,59 +13,59 @@ crate::http::header::common_header! {
test_parse_and_format {
crate::http::header::common_header_test!(test_bytes,
vec![b"bytes 0-499/500"],
[b"bytes 0-499/500"],
Some(ContentRange(ContentRangeSpec::Bytes {
range: Some((0, 499)),
instance_length: Some(500)
})));
crate::http::header::common_header_test!(test_bytes_unknown_len,
vec![b"bytes 0-499/*"],
[b"bytes 0-499/*"],
Some(ContentRange(ContentRangeSpec::Bytes {
range: Some((0, 499)),
instance_length: None
})));
crate::http::header::common_header_test!(test_bytes_unknown_range,
vec![b"bytes */500"],
[b"bytes */500"],
Some(ContentRange(ContentRangeSpec::Bytes {
range: None,
instance_length: Some(500)
})));
crate::http::header::common_header_test!(test_unregistered,
vec![b"seconds 1-2"],
[b"seconds 1-2"],
Some(ContentRange(ContentRangeSpec::Unregistered {
unit: "seconds".to_owned(),
resp: "1-2".to_owned()
})));
crate::http::header::common_header_test!(test_no_len,
vec![b"bytes 0-499"],
[b"bytes 0-499"],
None::<ContentRange>);
crate::http::header::common_header_test!(test_only_unit,
vec![b"bytes"],
[b"bytes"],
None::<ContentRange>);
crate::http::header::common_header_test!(test_end_less_than_start,
vec![b"bytes 499-0/500"],
[b"bytes 499-0/500"],
None::<ContentRange>);
crate::http::header::common_header_test!(test_blank,
vec![b""],
[b""],
None::<ContentRange>);
crate::http::header::common_header_test!(test_bytes_many_spaces,
vec![b"bytes 1-2/500 3"],
[b"bytes 1-2/500 3"],
None::<ContentRange>);
crate::http::header::common_header_test!(test_bytes_many_slashes,
vec![b"bytes 1-2/500/600"],
[b"bytes 1-2/500/600"],
None::<ContentRange>);
crate::http::header::common_header_test!(test_bytes_many_dashes,
vec![b"bytes 1-2-3/500"],
[b"bytes 1-2-3/500"],
None::<ContentRange>);
}
@ -113,21 +113,13 @@ pub enum ContentRangeSpec {
},
}
fn split_in_two(s: &str, separator: char) -> Option<(&str, &str)> {
let mut iter = s.splitn(2, separator);
match (iter.next(), iter.next()) {
(Some(a), Some(b)) => Some((a, b)),
_ => None,
}
}
impl FromStr for ContentRangeSpec {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, ParseError> {
let res = match split_in_two(s, ' ') {
let res = match s.split_once(' ') {
Some(("bytes", resp)) => {
let (range, instance_length) = split_in_two(resp, '/').ok_or(ParseError::Header)?;
let (range, instance_length) = resp.split_once('/').ok_or(ParseError::Header)?;
let instance_length = if instance_length == "*" {
None
@ -139,7 +131,7 @@ impl FromStr for ContentRangeSpec {
None
} else {
let (first_byte, last_byte) =
split_in_two(range, '-').ok_or(ParseError::Header)?;
range.split_once('-').ok_or(ParseError::Header)?;
let first_byte = first_byte.parse().map_err(|_| ParseError::Header)?;
let last_byte = last_byte.parse().map_err(|_| ParseError::Header)?;
if last_byte < first_byte {

View File

@ -45,11 +45,11 @@ crate::http::header::common_header! {
test_parse_and_format {
crate::http::header::common_header_test!(
test_text_html,
vec![b"text/html"],
[b"text/html"],
Some(HeaderField(mime::TEXT_HTML)));
crate::http::header::common_header_test!(
test_image_star,
vec![b"image/*"],
[b"image/*"],
Some(HeaderField(mime::IMAGE_STAR)));
}

View File

@ -32,7 +32,7 @@ crate::http::header::common_header! {
(Date, DATE) => [HttpDate]
test_parse_and_format {
crate::http::header::common_header_test!(test1, vec![b"Tue, 15 Nov 1994 08:12:31 GMT"]);
crate::http::header::common_header_test!(test1, [b"Tue, 15 Nov 1994 08:12:31 GMT"]);
}
}

View File

@ -49,50 +49,50 @@ crate::http::header::common_header! {
test_parse_and_format {
// From the RFC
crate::http::header::common_header_test!(test1,
vec![b"\"xyzzy\""],
[b"\"xyzzy\""],
Some(ETag(EntityTag::new_strong("xyzzy".to_owned()))));
crate::http::header::common_header_test!(test2,
vec![b"W/\"xyzzy\""],
[b"W/\"xyzzy\""],
Some(ETag(EntityTag::new_weak("xyzzy".to_owned()))));
crate::http::header::common_header_test!(test3,
vec![b"\"\""],
[b"\"\""],
Some(ETag(EntityTag::new_strong("".to_owned()))));
// Own tests
crate::http::header::common_header_test!(test4,
vec![b"\"foobar\""],
[b"\"foobar\""],
Some(ETag(EntityTag::new_strong("foobar".to_owned()))));
crate::http::header::common_header_test!(test5,
vec![b"\"\""],
[b"\"\""],
Some(ETag(EntityTag::new_strong("".to_owned()))));
crate::http::header::common_header_test!(test6,
vec![b"W/\"weak-etag\""],
[b"W/\"weak-etag\""],
Some(ETag(EntityTag::new_weak("weak-etag".to_owned()))));
crate::http::header::common_header_test!(test7,
vec![b"W/\"\x65\x62\""],
[b"W/\"\x65\x62\""],
Some(ETag(EntityTag::new_weak("\u{0065}\u{0062}".to_owned()))));
crate::http::header::common_header_test!(test8,
vec![b"W/\"\""],
[b"W/\"\""],
Some(ETag(EntityTag::new_weak("".to_owned()))));
crate::http::header::common_header_test!(test9,
vec![b"no-dquotes"],
[b"no-dquotes"],
None::<ETag>);
crate::http::header::common_header_test!(test10,
vec![b"w/\"the-first-w-is-case-sensitive\""],
[b"w/\"the-first-w-is-case-sensitive\""],
None::<ETag>);
crate::http::header::common_header_test!(test11,
vec![b""],
[b""],
None::<ETag>);
crate::http::header::common_header_test!(test12,
vec![b"\"unmatched-dquotes1"],
[b"\"unmatched-dquotes1"],
None::<ETag>);
crate::http::header::common_header_test!(test13,
vec![b"unmatched-dquotes2\""],
[b"unmatched-dquotes2\""],
None::<ETag>);
crate::http::header::common_header_test!(test14,
vec![b"matched-\"dquotes\""],
[b"matched-\"dquotes\""],
None::<ETag>);
crate::http::header::common_header_test!(test15,
vec![b"\""],
[b"\""],
None::<ETag>);
}
}

View File

@ -36,6 +36,6 @@ crate::http::header::common_header! {
test_parse_and_format {
// Test case from RFC
crate::http::header::common_header_test!(test1, vec![b"Thu, 01 Dec 1994 16:00:00 GMT"]);
crate::http::header::common_header_test!(test1, [b"Thu, 01 Dec 1994 16:00:00 GMT"]);
}
}

View File

@ -52,17 +52,17 @@ common_header! {
test_parse_and_format {
crate::http::header::common_header_test!(
test1,
vec![b"\"xyzzy\""],
[b"\"xyzzy\""],
Some(HeaderField::Items(
vec![EntityTag::new_strong("xyzzy".to_owned())])));
crate::http::header::common_header_test!(
test2,
vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
[b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
Some(HeaderField::Items(
vec![EntityTag::new_strong("xyzzy".to_owned()),
EntityTag::new_strong("r2d2xxxx".to_owned()),
EntityTag::new_strong("c3piozzzz".to_owned())])));
crate::http::header::common_header_test!(test3, vec![b"*"], Some(IfMatch::Any));
crate::http::header::common_header_test!(test3, [b"*"], Some(IfMatch::Any));
}
}

View File

@ -35,6 +35,6 @@ crate::http::header::common_header! {
test_parse_and_format {
// Test case from RFC
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
crate::http::header::common_header_test!(test1, [b"Sat, 29 Oct 1994 19:43:31 GMT"]);
}
}

View File

@ -52,11 +52,11 @@ crate::http::header::common_header! {
(IfNoneMatch, IF_NONE_MATCH) => {Any / (EntityTag)+}
test_parse_and_format {
crate::http::header::common_header_test!(test1, vec![b"\"xyzzy\""]);
crate::http::header::common_header_test!(test2, vec![b"W/\"xyzzy\""]);
crate::http::header::common_header_test!(test3, vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""]);
crate::http::header::common_header_test!(test4, vec![b"W/\"xyzzy\", W/\"r2d2xxxx\", W/\"c3piozzzz\""]);
crate::http::header::common_header_test!(test5, vec![b"*"]);
crate::http::header::common_header_test!(test1, [b"\"xyzzy\""]);
crate::http::header::common_header_test!(test2, [b"W/\"xyzzy\""]);
crate::http::header::common_header_test!(test3, [b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""]);
crate::http::header::common_header_test!(test4, [b"W/\"xyzzy\", W/\"r2d2xxxx\", W/\"c3piozzzz\""]);
crate::http::header::common_header_test!(test5, [b"*"]);
}
}

View File

@ -111,7 +111,7 @@ mod test_parse_and_format {
use super::IfRange as HeaderField;
use crate::http::header::*;
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
crate::http::header::common_header_test!(test2, vec![b"\"abc\""]);
crate::http::header::common_header_test!(test3, vec![b"this-is-invalid"], None::<IfRange>);
crate::http::header::common_header_test!(test1, [b"Sat, 29 Oct 1994 19:43:31 GMT"]);
crate::http::header::common_header_test!(test2, [b"\"abc\""]);
crate::http::header::common_header_test!(test3, [b"this-is-invalid"], None::<IfRange>);
}

View File

@ -35,6 +35,6 @@ crate::http::header::common_header! {
test_parse_and_format {
// Test case from RFC
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
crate::http::header::common_header_test!(test1, [b"Sat, 29 Oct 1994 19:43:31 GMT"]);
}
}

View File

@ -34,6 +34,6 @@ crate::http::header::common_header! {
test_parse_and_format {
// Test case from RFC
crate::http::header::common_header_test!(test1, vec![b"Sat, 29 Oct 1994 19:43:31 GMT"]);
crate::http::header::common_header_test!(test1, [b"Sat, 29 Oct 1994 19:43:31 GMT"]);
}
}