mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 12:35:28 +00:00
Switch from lazy_static to once_cell
This commit is contained in:
parent
8e13714011
commit
7588b23fcb
3 changed files with 8 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -6,7 +6,7 @@ version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-tls",
|
"async-tls",
|
||||||
"lazy_static",
|
"once_cell",
|
||||||
"rustls",
|
"rustls",
|
||||||
"tree_magic",
|
"tree_magic",
|
||||||
"url",
|
"url",
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ edition = "2018"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-tls = "0.7.0"
|
async-tls = "0.7.0"
|
||||||
async-std = "1.5"
|
async-std = "1.5"
|
||||||
lazy_static = "1.4"
|
once_cell = "1.4"
|
||||||
rustls = "0.17.0"
|
rustls = "0.17.0"
|
||||||
tree_magic = "0.2.3"
|
tree_magic = "0.2.3"
|
||||||
url = "2.1"
|
url = "2.1"
|
||||||
|
|
|
||||||
14
src/main.rs
14
src/main.rs
|
|
@ -7,7 +7,7 @@ use {
|
||||||
task,
|
task,
|
||||||
},
|
},
|
||||||
async_tls::TlsAcceptor,
|
async_tls::TlsAcceptor,
|
||||||
lazy_static::lazy_static,
|
once_cell::sync::Lazy,
|
||||||
std::{error::Error, ffi::OsStr, marker::Unpin, str, sync::Arc},
|
std::{error::Error, ffi::OsStr, marker::Unpin, str, sync::Arc},
|
||||||
url::Url,
|
url::Url,
|
||||||
};
|
};
|
||||||
|
|
@ -36,12 +36,6 @@ fn main() -> Result {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref ARGS: Args = args()
|
|
||||||
.expect("usage: agate <addr:port> <dir> <cert> <key>");
|
|
||||||
static ref ACCEPTOR: TlsAcceptor = acceptor().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn args() -> Option<Args> {
|
fn args() -> Option<Args> {
|
||||||
let mut args = std::env::args().skip(1);
|
let mut args = std::env::args().skip(1);
|
||||||
Some(Args {
|
Some(Args {
|
||||||
|
|
@ -52,6 +46,9 @@ fn args() -> Option<Args> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ARGS: Lazy<Args> =
|
||||||
|
Lazy::new(|| args().expect("usage: agate <addr:port> <dir> <cert> <key>"));
|
||||||
|
|
||||||
fn acceptor() -> Result<TlsAcceptor> {
|
fn acceptor() -> Result<TlsAcceptor> {
|
||||||
use rustls::{ServerConfig, NoClientAuth, internal::pemfile::{certs, pkcs8_private_keys}};
|
use rustls::{ServerConfig, NoClientAuth, internal::pemfile::{certs, pkcs8_private_keys}};
|
||||||
use std::{io::BufReader, fs::File};
|
use std::{io::BufReader, fs::File};
|
||||||
|
|
@ -69,7 +66,8 @@ fn acceptor() -> Result<TlsAcceptor> {
|
||||||
|
|
||||||
/// Handle a single client session (request + response).
|
/// Handle a single client session (request + response).
|
||||||
async fn connection(stream: TcpStream) -> Result {
|
async fn connection(stream: TcpStream) -> Result {
|
||||||
use async_std::io::prelude::*;
|
static ACCEPTOR: Lazy<TlsAcceptor> = Lazy::new(|| acceptor().unwrap());
|
||||||
|
|
||||||
let mut stream = ACCEPTOR.accept(stream).await?;
|
let mut stream = ACCEPTOR.accept(stream).await?;
|
||||||
match parse_request(&mut stream).await {
|
match parse_request(&mut stream).await {
|
||||||
Ok(url) => {
|
Ok(url) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue