♻️ Extract crate ptth_core
parent
64a0d90762
commit
84bb326f37
|
@ -14,7 +14,6 @@ aho-corasick = "0.7.14"
|
||||||
base64 = "0.12.3"
|
base64 = "0.12.3"
|
||||||
blake3 = "0.3.7"
|
blake3 = "0.3.7"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
ctrlc = { version = "3.1.7", features = [ "termination" ] }
|
|
||||||
dashmap = "3.11.10"
|
dashmap = "3.11.10"
|
||||||
futures = "0.3.7"
|
futures = "0.3.7"
|
||||||
handlebars = "3.5.1"
|
handlebars = "3.5.1"
|
||||||
|
@ -41,6 +40,7 @@ ulid = "0.4.1"
|
||||||
url = "2.2.0"
|
url = "2.2.0"
|
||||||
|
|
||||||
always_equal = { path = "crates/always_equal" }
|
always_equal = { path = "crates/always_equal" }
|
||||||
|
ptth_core = { path = "crates/ptth_core" }
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
[package]
|
||||||
|
|
||||||
|
name = "ptth_core"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Trish"]
|
||||||
|
edition = "2018"
|
||||||
|
license = "AGPL-3.0"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
ctrlc = { version = "3.1.7", features = [ "termination" ] }
|
||||||
|
futures = "0.3.7"
|
||||||
|
hyper = "0.13.8"
|
||||||
|
serde = {version = "1.0.117", features = ["derive"]}
|
||||||
|
tokio = { version = "0.2.22", features = ["full"] }
|
||||||
|
tracing = "0.1.21"
|
||||||
|
tracing-futures = "0.2.4"
|
|
@ -0,0 +1,16 @@
|
||||||
|
pub mod graceful_shutdown;
|
||||||
|
pub mod http_serde;
|
||||||
|
pub mod prelude;
|
||||||
|
|
||||||
|
// The arguments are in order so they are in order overall:
|
||||||
|
// e.g. prefix_match ("/prefix", "/prefix/middle/suffix") -> "/middle/suffix"
|
||||||
|
|
||||||
|
pub fn prefix_match <'a> (prefix: &str, hay: &'a str) -> Option <&'a str>
|
||||||
|
{
|
||||||
|
if hay.starts_with (prefix) {
|
||||||
|
Some (&hay [prefix.len ()..])
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
pub use tracing::{
|
||||||
|
debug, error, info, trace, warn,
|
||||||
|
instrument,
|
||||||
|
};
|
|
@ -18,11 +18,11 @@ use hyper::{
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use ptth::{
|
use ptth_core::{
|
||||||
http_serde::RequestParts,
|
http_serde::RequestParts,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
server::file_server,
|
|
||||||
};
|
};
|
||||||
|
use ptth::server::file_server;
|
||||||
|
|
||||||
#[derive (Default)]
|
#[derive (Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
@ -133,7 +133,7 @@ async fn main () -> Result <(), Box <dyn Error>> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let (shutdown_rx, forced_shutdown) = ptth::graceful_shutdown::init_with_force ();
|
let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();
|
||||||
|
|
||||||
let server = Server::bind (&addr)
|
let server = Server::bind (&addr)
|
||||||
.serve (make_svc)
|
.serve (make_svc)
|
||||||
|
|
|
@ -30,7 +30,7 @@ async fn main () -> Result <(), Box <dyn Error>> {
|
||||||
|
|
||||||
info! ("ptth_relay Git version: {:?}", ptth::relay::git_version::GIT_VERSION);
|
info! ("ptth_relay Git version: {:?}", ptth::relay::git_version::GIT_VERSION);
|
||||||
|
|
||||||
let (shutdown_rx, forced_shutdown) = ptth::graceful_shutdown::init_with_force ();
|
let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();
|
||||||
|
|
||||||
forced_shutdown.wrap_server (
|
forced_shutdown.wrap_server (
|
||||||
relay::run_relay (
|
relay::run_relay (
|
||||||
|
|
|
@ -51,7 +51,7 @@ fn main () -> Result <(), Box <dyn Error>> {
|
||||||
rt.block_on (async move {
|
rt.block_on (async move {
|
||||||
ptth::server::run_server (
|
ptth::server::run_server (
|
||||||
config_file,
|
config_file,
|
||||||
ptth::graceful_shutdown::init (),
|
ptth_core::graceful_shutdown::init (),
|
||||||
Some (path),
|
Some (path),
|
||||||
opt.asset_root
|
opt.asset_root
|
||||||
).await
|
).await
|
||||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -5,24 +5,8 @@
|
||||||
|
|
||||||
pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4";
|
pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4";
|
||||||
|
|
||||||
pub mod graceful_shutdown;
|
|
||||||
pub mod http_serde;
|
|
||||||
pub mod prelude;
|
|
||||||
pub mod relay;
|
pub mod relay;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
|
|
||||||
// The arguments are in order so they are in order overall:
|
|
||||||
// e.g. prefix_match ("/prefix", "/prefix/middle/suffix") -> "/middle/suffix"
|
|
||||||
|
|
||||||
pub fn prefix_match <'a> (prefix: &str, hay: &'a str) -> Option <&'a str>
|
|
||||||
{
|
|
||||||
if hay.starts_with (prefix) {
|
|
||||||
Some (&hay [prefix.len ()..])
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg (test)]
|
#[cfg (test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
pub use tracing::{debug, error, info, trace, warn};
|
|
|
@ -40,14 +40,11 @@ use tokio::{
|
||||||
},
|
},
|
||||||
time::delay_for,
|
time::delay_for,
|
||||||
};
|
};
|
||||||
use tracing::{
|
|
||||||
debug, error, info, trace,
|
|
||||||
instrument,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use ptth_core::{
|
||||||
http_serde,
|
http_serde,
|
||||||
prefix_match,
|
prefix_match,
|
||||||
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
|
@ -36,7 +36,7 @@ use always_equal::test::AlwaysEqual;
|
||||||
#[cfg (not (test))]
|
#[cfg (not (test))]
|
||||||
use always_equal::prod::AlwaysEqual;
|
use always_equal::prod::AlwaysEqual;
|
||||||
|
|
||||||
use crate::{
|
use ptth_core::{
|
||||||
http_serde::{
|
http_serde::{
|
||||||
Method,
|
Method,
|
||||||
Response,
|
Response,
|
||||||
|
@ -796,9 +796,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn file_server () {
|
fn file_server () {
|
||||||
use crate::{
|
use ptth_core::{
|
||||||
http_serde::Method,
|
http_serde::Method,
|
||||||
//prelude::*,
|
|
||||||
};
|
};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ use tokio::{
|
||||||
time::delay_for,
|
time::delay_for,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use ptth_core::{
|
||||||
http_serde,
|
http_serde,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue