diff --git a/Cargo.lock b/Cargo.lock index aab3217..49d757d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,7 +6,7 @@ version = "1.1.0" dependencies = [ "async-std", "async-tls", - "lazy_static", + "once_cell", "rustls", "tree_magic", "url", diff --git a/Cargo.toml b/Cargo.toml index a22aa20..9938812 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" [dependencies] async-tls = "0.7.0" async-std = "1.5" -lazy_static = "1.4" +once_cell = "1.4" rustls = "0.17.0" tree_magic = "0.2.3" url = "2.1" diff --git a/src/main.rs b/src/main.rs index 9c7d330..09b574c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use { task, }, async_tls::TlsAcceptor, - lazy_static::lazy_static, + once_cell::sync::Lazy, std::{error::Error, ffi::OsStr, marker::Unpin, str, sync::Arc}, url::Url, }; @@ -36,12 +36,6 @@ fn main() -> Result { }) } -lazy_static! { - static ref ARGS: Args = args() - .expect("usage: agate "); - static ref ACCEPTOR: TlsAcceptor = acceptor().unwrap(); -} - fn args() -> Option { let mut args = std::env::args().skip(1); Some(Args { @@ -52,6 +46,9 @@ fn args() -> Option { }) } +static ARGS: Lazy = + Lazy::new(|| args().expect("usage: agate ")); + fn acceptor() -> Result { use rustls::{ServerConfig, NoClientAuth, internal::pemfile::{certs, pkcs8_private_keys}}; use std::{io::BufReader, fs::File}; @@ -69,7 +66,8 @@ fn acceptor() -> Result { /// Handle a single client session (request + response). async fn connection(stream: TcpStream) -> Result { - use async_std::io::prelude::*; + static ACCEPTOR: Lazy = Lazy::new(|| acceptor().unwrap()); + let mut stream = ACCEPTOR.accept(stream).await?; match parse_request(&mut stream).await { Ok(url) => {