From 435232bf6cbe5847ce2487a87c64ca5558fb2455 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 8 Nov 2020 16:00:31 +0000 Subject: [PATCH] :recycle: Use a prelude to clean up the unused imports for `tracing` --- src/bin/ptth_file_server.rs | 4 +--- src/graceful_shutdown.rs | 3 ++- src/lib.rs | 7 ++----- src/prelude.rs | 1 + src/server/file_server.rs | 6 ++---- src/server/mod.rs | 11 +---------- todo.md | 1 + 7 files changed, 10 insertions(+), 23 deletions(-) create mode 100644 src/prelude.rs diff --git a/src/bin/ptth_file_server.rs b/src/bin/ptth_file_server.rs index 2f638bc..8291428 100644 --- a/src/bin/ptth_file_server.rs +++ b/src/bin/ptth_file_server.rs @@ -17,12 +17,10 @@ use hyper::{ StatusCode, }; use serde::Deserialize; -use tracing::{ - debug, error, info, trace, warn, -}; use ptth::{ http_serde::RequestParts, + prelude::*, server::file_server, }; diff --git a/src/graceful_shutdown.rs b/src/graceful_shutdown.rs index c1917e6..992414e 100644 --- a/src/graceful_shutdown.rs +++ b/src/graceful_shutdown.rs @@ -8,7 +8,8 @@ use tokio::{ sync::oneshot, time::delay_for, }; -use tracing::{debug, error, info, trace, warn}; + +use crate::prelude::*; pub fn init () -> oneshot::Receiver <()> { let (tx, rx) = oneshot::channel::<()> (); diff --git a/src/lib.rs b/src/lib.rs index 12fc7b4..435bae3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -pub mod http_serde; - // It's easier if the server can stream its response body // back to the relay un-changed inside its request body // So we wrap the server's actual response head @@ -7,12 +5,11 @@ pub mod http_serde; pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4"; -// Basically binaries, but in the lib we can do experimental -// test stuff like spawn them both in the same process - pub mod git_version; pub mod graceful_shutdown; +pub mod http_serde; pub mod load_toml; +pub mod prelude; pub mod relay; pub mod server; diff --git a/src/prelude.rs b/src/prelude.rs new file mode 100644 index 0000000..f4af411 --- /dev/null +++ b/src/prelude.rs @@ -0,0 +1 @@ +pub use tracing::{debug, error, info, trace, warn}; diff --git a/src/server/file_server.rs b/src/server/file_server.rs index 35d9ac2..ec1b136 100644 --- a/src/server/file_server.rs +++ b/src/server/file_server.rs @@ -23,15 +23,13 @@ use tokio::{ channel, }, }; -use tracing::{ - debug, error, info, trace, warn, - instrument, -}; +use tracing::instrument; use regex::Regex; use crate::{ http_serde, + prelude::*, prefix_match, }; diff --git a/src/server/mod.rs b/src/server/mod.rs index 6b9f06b..7b5cdcd 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -16,11 +16,10 @@ use tokio::{ sync::oneshot, time::delay_for, }; -use tracing::{debug, error, info, warn}; use crate::{ http_serde, - prefix_match, + prelude::*, }; pub mod file_server; @@ -32,14 +31,6 @@ struct ServerState { hidden_path: Option , } -fn status_reply (c: http_serde::StatusCode, body: &str) -> http_serde::Response -{ - let mut r = http_serde::Response::default (); - r.status_code (c) - .body_bytes (body.as_bytes ().to_vec ()); - r -} - async fn handle_req_resp <'a> ( state: &Arc , req_resp: reqwest::Response diff --git a/todo.md b/todo.md index 0064c5b..398278c 100644 --- a/todo.md +++ b/todo.md @@ -1,6 +1,7 @@ - Not working behind Nginx (Works okay behind Caddy) - Reduce idle memory use? +- Compress bad passwords file - Package templates into exe for release - Redirect to add trailing slashes - Add file size in directory listing