Skip to content

Commit

Permalink
use async fn in trait to replace TAIT
Browse files Browse the repository at this point in the history
  • Loading branch information
rainj-me committed Nov 16, 2023
1 parent a1756f5 commit 3183727
Show file tree
Hide file tree
Showing 9 changed files with 707 additions and 588 deletions.
1,211 changes: 655 additions & 556 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ resolver = "2"

[workspace.dependencies]
monoio = "0.2.0"
monoio-http = { path = "../monoio-http/monoio-http" }
monoio-http-client = { path = "../monoio-http/monoio-http-client" }
monoio-native-tls = { path = "../monoio-tls/monoio-native-tls" }
monoio-rustls = { path = "../monoio-tls/monoio-rustls" }
monoio-http = "0.3.0"
monoio-http-client = "0.3.0"
monoio-native-tls = "0.3.0"
monoio-rustls = "0.3.0"
native-tls = "0.2"
service-async = { path = "../service-async/service-async" }
certain-map = { path = "../certain-map/certain-map" }
service-async = "0.2.0"
certain-map = "0.2.4"
local-sync = "0.1"
http = "1.0"
anyhow = "1"
serde = "1"
tracing = "0.1"

[profile.release-lto]
inherits = "release"
Expand Down
6 changes: 4 additions & 2 deletions examples/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[runtime]
# runtime_type = "legacy"
workers = 1
entries = 8192
entries = 1024


[servers.server_basic]
Expand Down Expand Up @@ -60,7 +60,9 @@ listener = { type = "socket", value = "0.0.0.0:8082" }

[[servers.server3.routes]]
path = '/'
upstreams = [{ endpoint = { type = "uri", value = "https://rsproxy.cn" } }]
upstreams = [
{ endpoint = { type = "uri", value = "https://www.wikipedia.org" } },
]


[servers.server4]
Expand Down
11 changes: 4 additions & 7 deletions monolake-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ proxy-protocol = []
monoio = { workspace = true, features = ["splice", "sync"] }
monoio-http = { workspace = true }
service-async = { workspace = true }

anyhow = "1"
tracing = "0.1"
http = { workspace = true }
anyhow = { workspace = true }
serde = { workspace = true, features = ["derive"] }
tracing = { workspace = true }

# futures
futures-util = { version = "0.3", features = ["sink"] }
futures-channel = { version = "0.3", features = ["sink"] }

http = "0.2"
http-serde = "1"
serde = "1"

sha2 = "0"
hex = "0"
derive_more = "0.99.0"
Expand Down
1 change: 1 addition & 0 deletions monolake-core/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::Path;
use monoio::buf::IoBufMut;

pub mod hash;
pub mod uri_serde;

pub async fn file_read(path: impl AsRef<Path>) -> std::io::Result<Vec<u8>> {
// since monoio has not support statx, we have to use std
Expand Down
17 changes: 17 additions & 0 deletions monolake-core/src/util/uri_serde.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use http::Uri;
use serde::{de, Deserialize, Deserializer, Serializer};

pub fn deserialize<'de, D>(deserializer: D) -> Result<Uri, D::Error>
where
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.parse().map_err(de::Error::custom)
}

pub fn serialize<S>(uri: &Uri, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&uri.to_string())
}
18 changes: 8 additions & 10 deletions monolake-services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,22 @@ monoio-http-client = { workspace = true, features = [
] }
local-sync = { workspace = true }
service-async = { workspace = true }
http = { workspace = true }
anyhow = { workspace = true }
serde = { workspace = true }
tracing = { workspace = true }

# tls
monoio-rustls = { workspace = true, optional = true }
rustls = { version = "0.21", optional = true }
rustls-pemfile = { version = "1", optional = true }
webpki-roots = { version = "0.25.2", optional = true }
monoio-native-tls = { workspace = true, optional = true }
native-tls = { workspace = true, optional = true }

rustls = { version = "0.21", optional = true, default-features = false }
rustls-pemfile = { version = "1", optional = true }
webpki-roots = { version = "0.25.2", optional = true }

# common
anyhow = "1"
tracing = "0.1"
http = "0.2"
bytes = "1"

http-serde = "1"
serde = "1"

async-channel = "1"
rand = "0.8"
matchit = "0.7"
Expand Down
7 changes: 5 additions & 2 deletions monolake-services/src/http/handlers/rewrite.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use http::{uri::Scheme, HeaderValue, Request, StatusCode, Version};
use matchit::Router;
use monoio_http::common::body::HttpBody;
use monolake_core::http::{HttpHandler, ResponseWithContinue};
use monolake_core::{
http::{HttpHandler, ResponseWithContinue},
util::uri_serde,
};
use rand::RngCore;
use serde::{Deserialize, Serialize};
use service_async::{
Expand Down Expand Up @@ -111,7 +114,7 @@ pub struct Upstream {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", content = "value", rename_all = "snake_case")]
pub enum Endpoint {
#[serde(with = "http_serde::uri")]
#[serde(with = "uri_serde")]
Uri(http::Uri),
Socket(std::net::SocketAddr),
Unix(std::path::PathBuf),
Expand Down
8 changes: 3 additions & 5 deletions monolake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ vendored = ["monolake-services/vendored"]
monoio = { workspace = true, features = ["sync", "async-cancel"] }
service-async = { workspace = true }
certain-map = { workspace = true }
anyhow = { workspace = true }
serde = { workspace = true }
tracing = { workspace = true }

monolake-core = { path = "../monolake-core" }
monolake-services = { path = "../monolake-services" }
Expand All @@ -27,15 +30,10 @@ monolake-services = { path = "../monolake-services" }
native-tls = { workspace = true, optional = true }
monoio-native-tls = { workspace = true, optional = true }

# error
anyhow = "1"

# log
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

# parse
clap = { version = "4", features = ['derive'] }
serde = "1"
serde_json = "1"
toml = "0"

0 comments on commit 3183727

Please sign in to comment.