mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
chore: address clippy warnings
This commit is contained in:
parent
1040bc3d17
commit
3eb5a059ad
@ -12,7 +12,7 @@ pub use self::{decoder::Decoder, encoder::Encoder};
|
|||||||
/// Special-purpose writer for streaming (de-)compression.
|
/// Special-purpose writer for streaming (de-)compression.
|
||||||
///
|
///
|
||||||
/// Pre-allocates 8KiB of capacity.
|
/// Pre-allocates 8KiB of capacity.
|
||||||
pub(self) struct Writer {
|
struct Writer {
|
||||||
buf: BytesMut,
|
buf: BytesMut,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_apply_mask() {
|
fn test_apply_mask() {
|
||||||
let mask = [0x6d, 0xb6, 0xb2, 0x80];
|
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,
|
0xf3, 0x00, 0x01, 0x02, 0x03, 0x80, 0x81, 0x82, 0xff, 0xfe, 0x00, 0x17, 0x74, 0xf9,
|
||||||
0x12, 0x03,
|
0x12, 0x03,
|
||||||
];
|
];
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#![allow(clippy::uninlined_format_args)]
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
convert::Infallible,
|
convert::Infallible,
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
@ -139,7 +137,7 @@ async fn expect_continue_h1() {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn chunked_payload() {
|
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 total_size: usize = chunk_sizes.iter().sum();
|
||||||
|
|
||||||
let mut srv = test_server(|| {
|
let mut srv = test_server(|| {
|
||||||
@ -402,7 +400,7 @@ async fn content_length() {
|
|||||||
let mut srv = test_server(|| {
|
let mut srv = test_server(|| {
|
||||||
HttpService::build()
|
HttpService::build()
|
||||||
.h1(|req: Request| {
|
.h1(|req: Request| {
|
||||||
let indx: usize = req.uri().path()[1..].parse().unwrap();
|
let idx: usize = req.uri().path()[1..].parse().unwrap();
|
||||||
let statuses = [
|
let statuses = [
|
||||||
StatusCode::NO_CONTENT,
|
StatusCode::NO_CONTENT,
|
||||||
StatusCode::CONTINUE,
|
StatusCode::CONTINUE,
|
||||||
@ -411,7 +409,7 @@ async fn content_length() {
|
|||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
StatusCode::NOT_FOUND,
|
StatusCode::NOT_FOUND,
|
||||||
];
|
];
|
||||||
ok::<_, Infallible>(Response::new(statuses[indx]))
|
ok::<_, Infallible>(Response::new(statuses[idx]))
|
||||||
})
|
})
|
||||||
.tcp()
|
.tcp()
|
||||||
})
|
})
|
||||||
|
@ -1529,7 +1529,12 @@ mod tests {
|
|||||||
assert!(!resource.resource_path_from_iter(&mut s, &mut ["item"].iter()));
|
assert!(!resource.resource_path_from_iter(&mut s, &mut ["item"].iter()));
|
||||||
|
|
||||||
let mut s = String::new();
|
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/");
|
assert_eq!(s, "/user/item/item2/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ common_header! {
|
|||||||
// Tests from the RFC
|
// Tests from the RFC
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test1,
|
test1,
|
||||||
vec![b"audio/*; q=0.2, audio/basic"],
|
[b"audio/*; q=0.2, audio/basic"],
|
||||||
Some(Accept(vec![
|
Some(Accept(vec![
|
||||||
QualityItem::new("audio/*".parse().unwrap(), q(0.2)),
|
QualityItem::new("audio/*".parse().unwrap(), q(0.2)),
|
||||||
QualityItem::max("audio/basic".parse().unwrap()),
|
QualityItem::max("audio/basic".parse().unwrap()),
|
||||||
@ -86,7 +86,7 @@ common_header! {
|
|||||||
|
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test2,
|
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![
|
Some(Accept(vec![
|
||||||
QualityItem::new(mime::TEXT_PLAIN, q(0.5)),
|
QualityItem::new(mime::TEXT_PLAIN, q(0.5)),
|
||||||
QualityItem::max(mime::TEXT_HTML),
|
QualityItem::max(mime::TEXT_HTML),
|
||||||
@ -99,13 +99,13 @@ common_header! {
|
|||||||
// Custom tests
|
// Custom tests
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test3,
|
test3,
|
||||||
vec![b"text/plain; charset=utf-8"],
|
[b"text/plain; charset=utf-8"],
|
||||||
Some(Accept(vec![
|
Some(Accept(vec![
|
||||||
QualityItem::max(mime::TEXT_PLAIN_UTF_8),
|
QualityItem::max(mime::TEXT_PLAIN_UTF_8),
|
||||||
])));
|
])));
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test4,
|
test4,
|
||||||
vec![b"text/plain; charset=utf-8; q=0.5"],
|
[b"text/plain; charset=utf-8; q=0.5"],
|
||||||
Some(Accept(vec![
|
Some(Accept(vec![
|
||||||
QualityItem::new(mime::TEXT_PLAIN_UTF_8, q(0.5)),
|
QualityItem::new(mime::TEXT_PLAIN_UTF_8, q(0.5)),
|
||||||
])));
|
])));
|
||||||
|
@ -57,6 +57,6 @@ common_header! {
|
|||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
// Test case from RFC
|
// 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"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,31 +50,31 @@ common_header! {
|
|||||||
(AcceptEncoding, header::ACCEPT_ENCODING) => (QualityItem<Preference<Encoding>>)*
|
(AcceptEncoding, header::ACCEPT_ENCODING) => (QualityItem<Preference<Encoding>>)*
|
||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
common_header_test!(no_headers, vec![b""; 0], Some(AcceptEncoding(vec![])));
|
common_header_test!(no_headers, [b""; 0], Some(AcceptEncoding(vec![])));
|
||||||
common_header_test!(empty_header, vec![b""; 1], Some(AcceptEncoding(vec![])));
|
common_header_test!(empty_header, [b""; 1], Some(AcceptEncoding(vec![])));
|
||||||
|
|
||||||
common_header_test!(
|
common_header_test!(
|
||||||
order_of_appearance,
|
order_of_appearance,
|
||||||
vec![b"br, gzip"],
|
[b"br, gzip"],
|
||||||
Some(AcceptEncoding(vec![
|
Some(AcceptEncoding(vec![
|
||||||
QualityItem::max(Preference::Specific(Encoding::brotli())),
|
QualityItem::max(Preference::Specific(Encoding::brotli())),
|
||||||
QualityItem::max(Preference::Specific(Encoding::gzip())),
|
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),
|
QualityItem::max(Preference::Any),
|
||||||
])));
|
])));
|
||||||
|
|
||||||
// Note: Removed quality 1 from gzip
|
// 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
|
// 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!(
|
common_header_test!(
|
||||||
only_gzip_no_identity,
|
only_gzip_no_identity,
|
||||||
vec![b"gzip, *; q=0"],
|
[b"gzip, *; q=0"],
|
||||||
Some(AcceptEncoding(vec![
|
Some(AcceptEncoding(vec![
|
||||||
QualityItem::max(Preference::Specific(Encoding::gzip())),
|
QualityItem::max(Preference::Specific(Encoding::gzip())),
|
||||||
QualityItem::zero(Preference::Any),
|
QualityItem::zero(Preference::Any),
|
||||||
|
@ -58,19 +58,19 @@ common_header! {
|
|||||||
(AcceptLanguage, header::ACCEPT_LANGUAGE) => (QualityItem<Preference<LanguageTag>>)*
|
(AcceptLanguage, header::ACCEPT_LANGUAGE) => (QualityItem<Preference<LanguageTag>>)*
|
||||||
|
|
||||||
test_parse_and_format {
|
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!(
|
common_header_test!(
|
||||||
example_from_rfc,
|
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!(
|
common_header_test!(
|
||||||
not_ordered_by_weight,
|
not_ordered_by_weight,
|
||||||
vec![b"en-US, en; q=0.5, fr"],
|
[b"en-US, en; q=0.5, fr"],
|
||||||
Some(AcceptLanguage(vec![
|
Some(AcceptLanguage(vec![
|
||||||
QualityItem::max("en-US".parse().unwrap()),
|
QualityItem::max("en-US".parse().unwrap()),
|
||||||
QualityItem::new("en".parse().unwrap(), q(0.5)),
|
QualityItem::new("en".parse().unwrap(), q(0.5)),
|
||||||
@ -80,7 +80,7 @@ common_header! {
|
|||||||
|
|
||||||
common_header_test!(
|
common_header_test!(
|
||||||
has_wildcard,
|
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![
|
Some(AcceptLanguage(vec![
|
||||||
QualityItem::max("fr-CH".parse().unwrap()),
|
QualityItem::max("fr-CH".parse().unwrap()),
|
||||||
QualityItem::new("fr".parse().unwrap(), q(0.9)),
|
QualityItem::new("fr".parse().unwrap(), q(0.9)),
|
||||||
@ -137,7 +137,7 @@ impl AcceptLanguage {
|
|||||||
b.quality.cmp(&a.quality)
|
b.quality.cmp(&a.quality)
|
||||||
});
|
});
|
||||||
|
|
||||||
types.into_iter().map(|qitem| qitem.item).collect()
|
types.into_iter().map(|q_item| q_item.item).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,12 +51,12 @@ crate::http::header::common_header! {
|
|||||||
// From the RFC
|
// From the RFC
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test1,
|
test1,
|
||||||
vec![b"GET, HEAD, PUT"],
|
[b"GET, HEAD, PUT"],
|
||||||
Some(HeaderField(vec![Method::GET, Method::HEAD, Method::PUT])));
|
Some(HeaderField(vec![Method::GET, Method::HEAD, Method::PUT])));
|
||||||
// Own tests
|
// Own tests
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test2,
|
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![
|
Some(HeaderField(vec![
|
||||||
Method::OPTIONS,
|
Method::OPTIONS,
|
||||||
Method::GET,
|
Method::GET,
|
||||||
@ -69,7 +69,7 @@ crate::http::header::common_header! {
|
|||||||
Method::PATCH])));
|
Method::PATCH])));
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test3,
|
test3,
|
||||||
vec![b""],
|
[b""],
|
||||||
Some(HeaderField(Vec::<Method>::new())));
|
Some(HeaderField(Vec::<Method>::new())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,13 +47,13 @@ common_header! {
|
|||||||
(CacheControl, header::CACHE_CONTROL) => (CacheDirective)+
|
(CacheControl, header::CACHE_CONTROL) => (CacheDirective)+
|
||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
common_header_test!(no_headers, vec![b""; 0], None);
|
common_header_test!(no_headers, [b""; 0], None);
|
||||||
common_header_test!(empty_header, vec![b""; 1], None);
|
common_header_test!(empty_header, [b""; 1], None);
|
||||||
common_header_test!(bad_syntax, vec![b"foo="], None);
|
common_header_test!(bad_syntax, [b"foo="], None);
|
||||||
|
|
||||||
common_header_test!(
|
common_header_test!(
|
||||||
multiple_headers,
|
multiple_headers,
|
||||||
vec![&b"no-cache"[..], &b"private"[..]],
|
[&b"no-cache"[..], &b"private"[..]],
|
||||||
Some(CacheControl(vec![
|
Some(CacheControl(vec![
|
||||||
CacheDirective::NoCache,
|
CacheDirective::NoCache,
|
||||||
CacheDirective::Private,
|
CacheDirective::Private,
|
||||||
@ -62,7 +62,7 @@ common_header! {
|
|||||||
|
|
||||||
common_header_test!(
|
common_header_test!(
|
||||||
argument,
|
argument,
|
||||||
vec![b"max-age=100, private"],
|
[b"max-age=100, private"],
|
||||||
Some(CacheControl(vec![
|
Some(CacheControl(vec![
|
||||||
CacheDirective::MaxAge(100),
|
CacheDirective::MaxAge(100),
|
||||||
CacheDirective::Private,
|
CacheDirective::Private,
|
||||||
@ -71,7 +71,7 @@ common_header! {
|
|||||||
|
|
||||||
common_header_test!(
|
common_header_test!(
|
||||||
extension,
|
extension,
|
||||||
vec![b"foo, bar=baz"],
|
[b"foo, bar=baz"],
|
||||||
Some(CacheControl(vec![
|
Some(CacheControl(vec![
|
||||||
CacheDirective::Extension("foo".to_owned(), None),
|
CacheDirective::Extension("foo".to_owned(), None),
|
||||||
CacheDirective::Extension("bar".to_owned(), Some("baz".to_owned())),
|
CacheDirective::Extension("bar".to_owned(), Some("baz".to_owned())),
|
||||||
|
@ -48,7 +48,7 @@ common_header! {
|
|||||||
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
(ContentLanguage, CONTENT_LANGUAGE) => (QualityItem<LanguageTag>)+
|
||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
crate::http::header::common_header_test!(test1, vec![b"da"]);
|
crate::http::header::common_header_test!(test1, [b"da"]);
|
||||||
crate::http::header::common_header_test!(test2, vec![b"mi, en"]);
|
crate::http::header::common_header_test!(test2, [b"mi, en"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,59 +13,59 @@ crate::http::header::common_header! {
|
|||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
crate::http::header::common_header_test!(test_bytes,
|
crate::http::header::common_header_test!(test_bytes,
|
||||||
vec![b"bytes 0-499/500"],
|
[b"bytes 0-499/500"],
|
||||||
Some(ContentRange(ContentRangeSpec::Bytes {
|
Some(ContentRange(ContentRangeSpec::Bytes {
|
||||||
range: Some((0, 499)),
|
range: Some((0, 499)),
|
||||||
instance_length: Some(500)
|
instance_length: Some(500)
|
||||||
})));
|
})));
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_bytes_unknown_len,
|
crate::http::header::common_header_test!(test_bytes_unknown_len,
|
||||||
vec![b"bytes 0-499/*"],
|
[b"bytes 0-499/*"],
|
||||||
Some(ContentRange(ContentRangeSpec::Bytes {
|
Some(ContentRange(ContentRangeSpec::Bytes {
|
||||||
range: Some((0, 499)),
|
range: Some((0, 499)),
|
||||||
instance_length: None
|
instance_length: None
|
||||||
})));
|
})));
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_bytes_unknown_range,
|
crate::http::header::common_header_test!(test_bytes_unknown_range,
|
||||||
vec![b"bytes */500"],
|
[b"bytes */500"],
|
||||||
Some(ContentRange(ContentRangeSpec::Bytes {
|
Some(ContentRange(ContentRangeSpec::Bytes {
|
||||||
range: None,
|
range: None,
|
||||||
instance_length: Some(500)
|
instance_length: Some(500)
|
||||||
})));
|
})));
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_unregistered,
|
crate::http::header::common_header_test!(test_unregistered,
|
||||||
vec![b"seconds 1-2"],
|
[b"seconds 1-2"],
|
||||||
Some(ContentRange(ContentRangeSpec::Unregistered {
|
Some(ContentRange(ContentRangeSpec::Unregistered {
|
||||||
unit: "seconds".to_owned(),
|
unit: "seconds".to_owned(),
|
||||||
resp: "1-2".to_owned()
|
resp: "1-2".to_owned()
|
||||||
})));
|
})));
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_no_len,
|
crate::http::header::common_header_test!(test_no_len,
|
||||||
vec![b"bytes 0-499"],
|
[b"bytes 0-499"],
|
||||||
None::<ContentRange>);
|
None::<ContentRange>);
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_only_unit,
|
crate::http::header::common_header_test!(test_only_unit,
|
||||||
vec![b"bytes"],
|
[b"bytes"],
|
||||||
None::<ContentRange>);
|
None::<ContentRange>);
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_end_less_than_start,
|
crate::http::header::common_header_test!(test_end_less_than_start,
|
||||||
vec![b"bytes 499-0/500"],
|
[b"bytes 499-0/500"],
|
||||||
None::<ContentRange>);
|
None::<ContentRange>);
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_blank,
|
crate::http::header::common_header_test!(test_blank,
|
||||||
vec![b""],
|
[b""],
|
||||||
None::<ContentRange>);
|
None::<ContentRange>);
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_bytes_many_spaces,
|
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>);
|
None::<ContentRange>);
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_bytes_many_slashes,
|
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>);
|
None::<ContentRange>);
|
||||||
|
|
||||||
crate::http::header::common_header_test!(test_bytes_many_dashes,
|
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>);
|
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 {
|
impl FromStr for ContentRangeSpec {
|
||||||
type Err = ParseError;
|
type Err = ParseError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, 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)) => {
|
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 == "*" {
|
let instance_length = if instance_length == "*" {
|
||||||
None
|
None
|
||||||
@ -139,7 +131,7 @@ impl FromStr for ContentRangeSpec {
|
|||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let (first_byte, last_byte) =
|
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 first_byte = first_byte.parse().map_err(|_| ParseError::Header)?;
|
||||||
let last_byte = last_byte.parse().map_err(|_| ParseError::Header)?;
|
let last_byte = last_byte.parse().map_err(|_| ParseError::Header)?;
|
||||||
if last_byte < first_byte {
|
if last_byte < first_byte {
|
||||||
|
@ -45,11 +45,11 @@ crate::http::header::common_header! {
|
|||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test_text_html,
|
test_text_html,
|
||||||
vec![b"text/html"],
|
[b"text/html"],
|
||||||
Some(HeaderField(mime::TEXT_HTML)));
|
Some(HeaderField(mime::TEXT_HTML)));
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test_image_star,
|
test_image_star,
|
||||||
vec![b"image/*"],
|
[b"image/*"],
|
||||||
Some(HeaderField(mime::IMAGE_STAR)));
|
Some(HeaderField(mime::IMAGE_STAR)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ crate::http::header::common_header! {
|
|||||||
(Date, DATE) => [HttpDate]
|
(Date, DATE) => [HttpDate]
|
||||||
|
|
||||||
test_parse_and_format {
|
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"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,50 +49,50 @@ crate::http::header::common_header! {
|
|||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
// From the RFC
|
// From the RFC
|
||||||
crate::http::header::common_header_test!(test1,
|
crate::http::header::common_header_test!(test1,
|
||||||
vec![b"\"xyzzy\""],
|
[b"\"xyzzy\""],
|
||||||
Some(ETag(EntityTag::new_strong("xyzzy".to_owned()))));
|
Some(ETag(EntityTag::new_strong("xyzzy".to_owned()))));
|
||||||
crate::http::header::common_header_test!(test2,
|
crate::http::header::common_header_test!(test2,
|
||||||
vec![b"W/\"xyzzy\""],
|
[b"W/\"xyzzy\""],
|
||||||
Some(ETag(EntityTag::new_weak("xyzzy".to_owned()))));
|
Some(ETag(EntityTag::new_weak("xyzzy".to_owned()))));
|
||||||
crate::http::header::common_header_test!(test3,
|
crate::http::header::common_header_test!(test3,
|
||||||
vec![b"\"\""],
|
[b"\"\""],
|
||||||
Some(ETag(EntityTag::new_strong("".to_owned()))));
|
Some(ETag(EntityTag::new_strong("".to_owned()))));
|
||||||
// Own tests
|
// Own tests
|
||||||
crate::http::header::common_header_test!(test4,
|
crate::http::header::common_header_test!(test4,
|
||||||
vec![b"\"foobar\""],
|
[b"\"foobar\""],
|
||||||
Some(ETag(EntityTag::new_strong("foobar".to_owned()))));
|
Some(ETag(EntityTag::new_strong("foobar".to_owned()))));
|
||||||
crate::http::header::common_header_test!(test5,
|
crate::http::header::common_header_test!(test5,
|
||||||
vec![b"\"\""],
|
[b"\"\""],
|
||||||
Some(ETag(EntityTag::new_strong("".to_owned()))));
|
Some(ETag(EntityTag::new_strong("".to_owned()))));
|
||||||
crate::http::header::common_header_test!(test6,
|
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()))));
|
Some(ETag(EntityTag::new_weak("weak-etag".to_owned()))));
|
||||||
crate::http::header::common_header_test!(test7,
|
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()))));
|
Some(ETag(EntityTag::new_weak("\u{0065}\u{0062}".to_owned()))));
|
||||||
crate::http::header::common_header_test!(test8,
|
crate::http::header::common_header_test!(test8,
|
||||||
vec![b"W/\"\""],
|
[b"W/\"\""],
|
||||||
Some(ETag(EntityTag::new_weak("".to_owned()))));
|
Some(ETag(EntityTag::new_weak("".to_owned()))));
|
||||||
crate::http::header::common_header_test!(test9,
|
crate::http::header::common_header_test!(test9,
|
||||||
vec![b"no-dquotes"],
|
[b"no-dquotes"],
|
||||||
None::<ETag>);
|
None::<ETag>);
|
||||||
crate::http::header::common_header_test!(test10,
|
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>);
|
None::<ETag>);
|
||||||
crate::http::header::common_header_test!(test11,
|
crate::http::header::common_header_test!(test11,
|
||||||
vec![b""],
|
[b""],
|
||||||
None::<ETag>);
|
None::<ETag>);
|
||||||
crate::http::header::common_header_test!(test12,
|
crate::http::header::common_header_test!(test12,
|
||||||
vec![b"\"unmatched-dquotes1"],
|
[b"\"unmatched-dquotes1"],
|
||||||
None::<ETag>);
|
None::<ETag>);
|
||||||
crate::http::header::common_header_test!(test13,
|
crate::http::header::common_header_test!(test13,
|
||||||
vec![b"unmatched-dquotes2\""],
|
[b"unmatched-dquotes2\""],
|
||||||
None::<ETag>);
|
None::<ETag>);
|
||||||
crate::http::header::common_header_test!(test14,
|
crate::http::header::common_header_test!(test14,
|
||||||
vec![b"matched-\"dquotes\""],
|
[b"matched-\"dquotes\""],
|
||||||
None::<ETag>);
|
None::<ETag>);
|
||||||
crate::http::header::common_header_test!(test15,
|
crate::http::header::common_header_test!(test15,
|
||||||
vec![b"\""],
|
[b"\""],
|
||||||
None::<ETag>);
|
None::<ETag>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,6 @@ crate::http::header::common_header! {
|
|||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
// Test case from RFC
|
// 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"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,17 +52,17 @@ common_header! {
|
|||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test1,
|
test1,
|
||||||
vec![b"\"xyzzy\""],
|
[b"\"xyzzy\""],
|
||||||
Some(HeaderField::Items(
|
Some(HeaderField::Items(
|
||||||
vec![EntityTag::new_strong("xyzzy".to_owned())])));
|
vec![EntityTag::new_strong("xyzzy".to_owned())])));
|
||||||
|
|
||||||
crate::http::header::common_header_test!(
|
crate::http::header::common_header_test!(
|
||||||
test2,
|
test2,
|
||||||
vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
|
[b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
|
||||||
Some(HeaderField::Items(
|
Some(HeaderField::Items(
|
||||||
vec![EntityTag::new_strong("xyzzy".to_owned()),
|
vec![EntityTag::new_strong("xyzzy".to_owned()),
|
||||||
EntityTag::new_strong("r2d2xxxx".to_owned()),
|
EntityTag::new_strong("r2d2xxxx".to_owned()),
|
||||||
EntityTag::new_strong("c3piozzzz".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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,6 @@ crate::http::header::common_header! {
|
|||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
// Test case from RFC
|
// 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"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,11 @@ crate::http::header::common_header! {
|
|||||||
(IfNoneMatch, IF_NONE_MATCH) => {Any / (EntityTag)+}
|
(IfNoneMatch, IF_NONE_MATCH) => {Any / (EntityTag)+}
|
||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
crate::http::header::common_header_test!(test1, vec![b"\"xyzzy\""]);
|
crate::http::header::common_header_test!(test1, [b"\"xyzzy\""]);
|
||||||
crate::http::header::common_header_test!(test2, vec![b"W/\"xyzzy\""]);
|
crate::http::header::common_header_test!(test2, [b"W/\"xyzzy\""]);
|
||||||
crate::http::header::common_header_test!(test3, vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""]);
|
crate::http::header::common_header_test!(test3, [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!(test4, [b"W/\"xyzzy\", W/\"r2d2xxxx\", W/\"c3piozzzz\""]);
|
||||||
crate::http::header::common_header_test!(test5, vec![b"*"]);
|
crate::http::header::common_header_test!(test5, [b"*"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ mod test_parse_and_format {
|
|||||||
use super::IfRange as HeaderField;
|
use super::IfRange as HeaderField;
|
||||||
use crate::http::header::*;
|
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!(test1, [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!(test2, [b"\"abc\""]);
|
||||||
crate::http::header::common_header_test!(test3, vec![b"this-is-invalid"], None::<IfRange>);
|
crate::http::header::common_header_test!(test3, [b"this-is-invalid"], None::<IfRange>);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,6 @@ crate::http::header::common_header! {
|
|||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
// Test case from RFC
|
// 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"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,6 @@ crate::http::header::common_header! {
|
|||||||
|
|
||||||
test_parse_and_format {
|
test_parse_and_format {
|
||||||
// Test case from RFC
|
// 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"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user