Follow Clippy

pull/8/head
Kitaiti Makoto 1 year ago
parent 8758b8c5c1
commit 48c861afc8

@ -248,7 +248,7 @@ impl CsrfFairingBuilder {
exceptions: self
.exceptions
.iter()
.map(|(a, b, m)| (Path::from(&a), Path::from(&b), *m))//TODO verify if source and target are compatible
.map(|(a, b, m)| (Path::from(a), Path::from(b), *m))//TODO verify if source and target are compatible
.collect(),
secret,
auto_insert: self.auto_insert,
@ -348,7 +348,7 @@ impl Fairing for CsrfFairing {
}
})
.next()
}.and_then(|token| BASE64URL_NOPAD.decode(&token).ok());
}.and_then(|token| BASE64URL_NOPAD.decode(token).ok());
let token = token.as_mut().and_then(|token| csrf_engine.parse_token(&mut *token).ok());
if let Some(token) = token {
@ -388,7 +388,7 @@ impl Fairing for CsrfFairing {
request.set_method(self.default_target.1)
}
fn on_response<'a>(&self, request: &Request, response: &mut Response<'a>) {
fn on_response(&self, request: &Request, response: &mut Response) {
if let Some(ct) = response.content_type() {
if !ct.is_html() {
return;
@ -412,7 +412,7 @@ impl Fairing for CsrfFairing {
Outcome::Forward(_) => {
if request.cookies().get(CSRF_COOKIE_NAME).is_some() {
response.adjoin_header(
&Cookie::build(CSRF_COOKIE_NAME, "")
Cookie::build(CSRF_COOKIE_NAME, "")
.max_age(Duration::zero())
.finish(),
);
@ -434,19 +434,19 @@ impl Fairing for CsrfFairing {
if len <= self.auto_insert_max_size {
//if this is a small enought body, process the full body
let mut res = Vec::with_capacity(len as usize);
CsrfProxy::from(body_reader, &token.value())
CsrfProxy::from(body_reader, token.value())
.read_to_end(&mut res)
.unwrap();
response.set_sized_body(Cursor::new(res));
} else {
//if body is of known but long size, change it to a stream to preserve memory, by encapsulating it into our "proxy" struct
let body = body_reader;
response.set_streamed_body(Box::new(CsrfProxy::from(body, &token.value())));
response.set_streamed_body(Box::new(CsrfProxy::from(body, token.value())));
}
} else {
//if body is of unknown size, encapsulate it into our "proxy" struct
let body = body.into_inner();
response.set_streamed_body(Box::new(CsrfProxy::from(body, &token.value())));
response.set_streamed_body(Box::new(CsrfProxy::from(body, token.value())));
}
}
}

@ -73,8 +73,8 @@ enum ParseState {
}
pub struct CsrfProxy<'a> {
underlying: Box<Read + 'a>, //the underlying Reader from which we get data
token: Vec<u8>, //a full input tag loaded with a valid token
underlying: Box<dyn Read + 'a>, //the underlying Reader from which we get data
token: Vec<u8>, //a full input tag loaded with a valid token
buf: Buffer,
unparsed: Vec<u8>,
state: ParseState, //state of the parser
@ -82,7 +82,7 @@ pub struct CsrfProxy<'a> {
}
impl<'a> CsrfProxy<'a> {
pub fn from(underlying: Box<Read + 'a>, token: &[u8]) -> Self {
pub fn from(underlying: Box<dyn Read + 'a>, token: &[u8]) -> Self {
let tag_begin = b"<input type=\"hidden\" name=\"csrf-token\" value=\"";
let tag_middle = token;
let tag_end = b"\"/>";

@ -60,7 +60,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for CsrfToken {
let mut buf = [0; 192];
match csrf_engine.generate_token_pair(token_value, *duration, &mut buf) {
Ok((token, cookie)) => {
let mut c =
let c =
Cookie::build(CSRF_COOKIE_NAME, BASE64URL_NOPAD.encode(cookie))
.http_only(true)
.secure(true)

@ -30,7 +30,7 @@ impl Path {
}
})
.collect();
let is_multidyn = |p: &PathPart| if let PathPart::MultiDynamic(_) = p { true } else {false};
let is_multidyn = |p: &PathPart| matches!(p, PathPart::MultiDynamic(_));
if !path.is_empty() && path[0..path.len() - 1].iter().any(is_multidyn) {
panic!("PathPart::MultiDynamic can only be found at end of path"); //TODO return error instead of panic
}
@ -55,7 +55,7 @@ impl Path {
Path { path, param }
}
pub fn extract<'a>(&self, uri: &'a str) -> Option<HashMap<&str, String>> {
pub fn extract(&self, uri: &str) -> Option<HashMap<&str, String>> {
//try to match a str against a path, give back a hashmap of correponding parts if it matched
let mut res: HashMap<&str, String> = HashMap::new();
let (path, query) = if let Some(pos) = uri.find('?') {
@ -165,7 +165,7 @@ impl Path {
res.push('&');
}
}
Some(res.trim_right_matches('&').to_owned()) //trim the last '&' which was added if there is a query part
Some(res.trim_end_matches('&').to_owned()) //trim the last '&' which was added if there is a query part
}
}

@ -1,6 +1,6 @@
pub fn parse_args(args: &str) -> impl Iterator<Item = (&str, &str)> {
//transform a group of argument into an iterator of key and value
args.split('&').filter_map(|kv| parse_keyvalue(&kv))
args.split('&').filter_map(parse_keyvalue)
}
fn parse_keyvalue(kv: &str) -> Option<(&str, &str)> {

Loading…
Cancel
Save