diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-10 17:21:53 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-10 17:21:53 +0200 |
commit | c88d6e280a669eca44b8331b8731cf5fc933a957 (patch) | |
tree | f089a5402808a281a13be7b58593aaa829c8e109 | |
parent | 6d0bac25aa3f118de34a9f05d939f60d80f550a5 (diff) | |
download | gnix-c88d6e280a669eca44b8331b8731cf5fc933a957.tar gnix-c88d6e280a669eca44b8331b8731cf5fc933a957.tar.bz2 gnix-c88d6e280a669eca44b8331b8731cf5fc933a957.tar.zst |
clippy
-rw-r--r-- | src/main.rs | 27 | ||||
-rw-r--r-- | src/modules/auth/mod.rs | 4 | ||||
-rw-r--r-- | src/modules/files.rs | 15 | ||||
-rw-r--r-- | src/modules/hosts.rs | 2 | ||||
-rw-r--r-- | src/modules/mod.rs | 2 |
5 files changed, 24 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs index 1d75d50..eecb946 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,14 +4,13 @@ pub mod config; pub mod error; -pub mod modules; pub mod helper; +pub mod modules; use aes_gcm_siv::{aead::generic_array::GenericArray, Aes256GcmSiv, KeyInit}; use anyhow::{anyhow, Context, Result}; use config::{setup_file_watch, Config, NODE_KINDS}; use error::ServiceError; -use modules::{NodeContext, MODULES}; use futures::future::try_join_all; use helper::TokioIo; use http_body_util::{combinators::BoxBody, BodyExt}; @@ -24,6 +23,7 @@ use hyper::{ Request, Response, StatusCode, }; use log::{debug, error, info, warn, LevelFilter}; +use modules::{NodeContext, MODULES}; use rustls::pki_types::{CertificateDer, PrivateKeyDer}; use std::{ collections::HashMap, @@ -63,7 +63,7 @@ async fn main() -> anyhow::Result<()> { .unwrap() .extend(MODULES.iter().map(|m| (m.name().to_owned(), *m))); - let Some(config_path) = std::env::args().skip(1).next() else { + let Some(config_path) = std::env::args().nth(1) else { eprintln!("error: first argument is expected to be the configuration file"); exit(1) }; @@ -122,7 +122,7 @@ async fn serve_http(state: Arc<State>) -> Result<()> { }; let listen_futs: Result<Vec<()>> = try_join_all(http_config.bind.iter().map(|e| async { - let l = TcpListener::bind(e.clone()).await?; + let l = TcpListener::bind(*e).await?; info!("HTTP listener bound to {}", l.local_addr().unwrap()); loop { let (stream, addr) = l.accept().await.context("accepting connection")?; @@ -160,7 +160,7 @@ async fn serve_https(state: Arc<State>) -> Result<()> { }; let tls_acceptor = Arc::new(TlsAcceptor::from(tls_config)); let listen_futs: Result<Vec<()>> = try_join_all(https_config.bind.iter().map(|e| async { - let l = TcpListener::bind(e.clone()).await?; + let l = TcpListener::bind(*e).await?; info!("HTTPS listener bound to {}", l.local_addr().unwrap()); loop { let (stream, addr) = l.accept().await.context("accepting connection")?; @@ -232,7 +232,7 @@ fn load_certs(path: &Path) -> anyhow::Result<Vec<CertificateDer<'static>>> { fn load_private_key(path: &Path) -> anyhow::Result<PrivateKeyDer<'static>> { let mut reader = BufReader::new(std::fs::File::open(path).context("reading tls private key")?); let keys = rustls_pemfile::private_key(&mut reader).context("parsing tls private key")?; - Ok(keys.ok_or(anyhow!("no private key found"))?) + keys.ok_or(anyhow!("no private key found")) } async fn service( @@ -253,13 +253,16 @@ async fn service( let server_header = resp.headers().get(SERVER).cloned(); resp.headers_mut().insert( SERVER, - HeaderValue::from_str(&if let Some(o) = server_header { - format!("{} via gnix", o.to_str().ok().unwrap_or("invalid")) + if let Some(o) = server_header { + HeaderValue::from_str(&format!( + "{} via gnix", + o.to_str().ok().unwrap_or("invalid") + )) + .unwrap() } else { - format!("gnix") - }) - .unwrap(), + HeaderValue::from_static("gnix") + }, ); - return Ok(resp); + Ok(resp) } diff --git a/src/modules/auth/mod.rs b/src/modules/auth/mod.rs index 715ca97..729ea42 100644 --- a/src/modules/auth/mod.rs +++ b/src/modules/auth/mod.rs @@ -64,9 +64,7 @@ impl<'de> Deserialize<'de> for Credentials { where A: MapAccess<'de>, { - Ok(HashMap::deserialize(value::MapAccessDeserializer::new( - val, - ))?) + HashMap::deserialize(value::MapAccessDeserializer::new(val)) } } let k = deserializer.deserialize_any(StringOrMap)?; diff --git a/src/modules/files.rs b/src/modules/files.rs index 4fdd5cd..607cee1 100644 --- a/src/modules/files.rs +++ b/src/modules/files.rs @@ -167,18 +167,15 @@ impl Node for Files { } else { Response::new(BoxBody::new(StreamBody::new( StreamBody::new(file_stream(file, 4096, range.clone())) - .map(|e| e.map(|e| Frame::data(e)).map_err(ServiceError::Io)), + .map(|e| e.map(Frame::data).map_err(ServiceError::Io)), ))) }; - if !skip_body { - if range.end - range.start != metadata.len() { - *r.status_mut() = StatusCode::PARTIAL_CONTENT; - r.headers_mut().typed_insert( - ContentRange::bytes(range.clone(), metadata.len()) - .expect("valid ContentRange"), - ); - } + if !skip_body && range.end - range.start != metadata.len() { + *r.status_mut() = StatusCode::PARTIAL_CONTENT; + r.headers_mut().typed_insert( + ContentRange::bytes(range.clone(), metadata.len()).expect("valid ContentRange"), + ); } // if not_modified || etag_matches { if not_modified { diff --git a/src/modules/hosts.rs b/src/modules/hosts.rs index 286d478..7ad7481 100644 --- a/src/modules/hosts.rs +++ b/src/modules/hosts.rs @@ -32,7 +32,7 @@ impl Node for Hosts { .and_then(|e| e.to_str().ok()) .ok_or(ServiceError::NoHost)?; - let host = remove_port(&host); + let host = remove_port(host); let node = self.0.get(host).ok_or(ServiceError::UnknownHost)?; node.handle(context, request).await diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 2bee8e3..d96c24b 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -25,7 +25,7 @@ pub mod proxy; pub type NodeRequest = Request<Incoming>; pub type NodeResponse = Response<BoxBody<Bytes, ServiceError>>; -pub static MODULES: &'static [&'static dyn NodeKind] = &[ +pub static MODULES: &[&dyn NodeKind] = &[ &HttpBasicAuthKind, &CookieAuthKind, &ProxyKind, |