Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Sep 28, 2022
1 parent 8f8eba8 commit 8eb0ceb
Show file tree
Hide file tree
Showing 21 changed files with 629 additions and 319 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Expand Up @@ -2,12 +2,13 @@
**/*.rs.bk
/Cargo.lock
/.idea
/site/public
/.vscode
**/target
/.vs
examples/_*.rs
examples/test
/examples/_*.rs
/examples/test
/examples/target
/examples/*/target
cobertura.xml
debug.log
temp
Expand Down
67 changes: 66 additions & 1 deletion Cargo.toml
@@ -1,2 +1,67 @@
[workspace]
members = ["crates/*", "examples/*"]
members = ["crates/*", "examples/*"]

[workspace.package]
version = "0.35.2"
authors = ["Chrislearn Young <chrislearn@hotmail.com>"]
edition = "2021"
description = """
Salvo is a powerful and simplest web server framework in Rust world.
"""
homepage = "https://salvo.rs"
repository = "https://github.com/salvo-rs/salvo"
documentation = "https://docs.rs/salvo/"
readme = "./README.md"
keywords = ["http", "async", "web", "framework", "server"]
license = "MIT OR Apache-2.0"
categories = ["web-programming::http-server", "web-programming::websocket", "network-programming", "asynchronous"]

[workspace.dependencies]
anyhow = "1"
async-session = "3"
async-trait = "0.1"
base64 = "0.13"
bytes = "1"
chrono = "0.4"
cookie = "0.16"
cruet = "0.13"
encoding_rs = "0.8"
enumflags2 = "0.7"
fastrand = "1.5"
form_urlencoded = "1"
futures-util = "0.3"
headers = "0.3"
http = "0.2"
hyper = "0.14"
hyper-rustls = "0.23"
mime = "0.3"
mime_guess = "2"
multimap = "0.8"
once_cell = "1"
path-slash = "0.2"
parking_lot = "0.12"
percent-encoding = "2"
pin-project = "1"
rand = "0.8"
regex = "1"
reqwest = "0.11"
rust-embed = "6"
salvo_macros = { version = "0.35.2", path = "./crates/macros" }
salvo_core = { version = "0.35.2", path = "./crates/core" }
salvo_extra = { version = "0.35.2", path = "./crates/extra" }
salvo-session = { version = "0.35.2", path = "./crates/session" }
serde = "1"
serde_json = "1"
serde_urlencoded = "0.7"
syn = "1"
thiserror = "1"
tokio = "1"
tokio-stream = "0.1"
tokio-util = "0.7"
tracing = "0.1"
tracing-test = "0.2.1"
url = "2"
darling = "0.14"
proc-macro-crate = "1"
proc-macro2 = "1"
quote = "1"
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -19,7 +19,7 @@
<a href="https://crates.io/crates/salvo"><img alt="crates.io" src="https://img.shields.io/crates/v/salvo" /></a>
<a href="https://docs.rs/salvo"><img alt="Documentation" src="https://docs.rs/salvo/badge.svg" /></a>
<a href="https://github.com/rust-secure-code/safety-dance/"><img alt="unsafe forbidden" src="https://img.shields.io/badge/unsafe-forbidden-success.svg" /></a>
<a href="https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.60%2B-blue" /></a>
<a href="https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.64%2B-blue" /></a>
<br>
<a href="https://salvo.rs">
<img alt="Website" src="https://img.shields.io/badge/https-salvo.rs-%23f00" />
Expand Down
2 changes: 1 addition & 1 deletion README.zh-hans.md
Expand Up @@ -19,7 +19,7 @@
<a href="https://crates.io/crates/salvo"><img alt="crates.io" src="https://img.shields.io/crates/v/salvo" /></a>
<a href="https://docs.rs/salvo"><img alt="Documentation" src="https://docs.rs/salvo/badge.svg" /></a>
<a href="https://github.com/rust-secure-code/safety-dance/"><img alt="unsafe forbidden" src="https://img.shields.io/badge/unsafe-forbidden-success.svg" /></a>
<a href="https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.60%2B-blue" /></a>
<a href="https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.64%2B-blue" /></a>
<br>
<a href="https://salvo.rs">
<img alt="Website" src="https://img.shields.io/badge/https-salvo.rs-%23f00" />
Expand Down
2 changes: 1 addition & 1 deletion README.zh-hant.md
Expand Up @@ -19,7 +19,7 @@
<a href="https://crates.io/crates/salvo"><img alt="crates.io" src="https://img.shields.io/crates/v/salvo" /></a>
<a href="https://docs.rs/salvo"><img alt="Documentation" src="https://docs.rs/salvo/badge.svg" /></a>
<a href="https://github.com/rust-secure-code/safety-dance/"><img alt="unsafe forbidden" src="https://img.shields.io/badge/unsafe-forbidden-success.svg" /></a>
<a href="https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.60%2B-blue" /></a>
<a href="https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html"><img alt="Rust Version" src="https://img.shields.io/badge/rust-1.64%2B-blue" /></a>
<br>
<a href="https://salvo.rs">
<img alt="Website" src="https://img.shields.io/badge/https-salvo.rs-%23f00" />
Expand Down
84 changes: 41 additions & 43 deletions crates/core/Cargo.toml
@@ -1,17 +1,15 @@
[package]
name = "salvo_core"
version = "0.35.2"
version.workspace = true
authors = ["Chrislearn Young <chrislearn@hotmail.com>", "driftluo <driftluo@foxmail.com>"]
edition = "2021"
description = """
Salvo is a powerful and simplest web server framework in Rust world.
"""
homepage = "https://salvo.rs"
repository = "https://github.com/salvo-rs/salvo"
readme = "../README.md"
keywords = ["http", "async", "web", "framework", "server"]
license = "MIT OR Apache-2.0"
categories = ["web-programming::http-server", "web-programming::websocket", "network-programming", "asynchronous"]
edition.workspace = true
description.workspace = true
homepage.workspace = true
repository.workspace = true
readme.workspace = true
keywords.workspace = true
license.workspace = true
categories.workspace = true

[package.metadata.docs.rs]
all-features = true
Expand All @@ -21,58 +19,58 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["cookie", "test"]
full = ["rustls", "anyhow"]
cookie = ["dep:cookie"]
rustls = ["dep:tokio-rustls", "dep:rustls-pemfile", "dep:pin-project-lite"]
native-tls = ["dep:tokio-native-tls", "dep:pin-project-lite"]
openssl = ["dep:openssl", "dep:pin-project-lite", "dep:tokio-openssl"]
rustls = ["dep:tokio-rustls", "dep:rustls-pemfile", "dep:pin-project"]
native-tls = ["dep:tokio-native-tls", "dep:pin-project"]
openssl = ["dep:openssl", "dep:pin-project", "dep:tokio-openssl"]
unix = []
test = ["dep:async-compression", "dep:base64", "dep:encoding_rs", "dep:serde_urlencoded", "dep:url", "tokio/macros"]
acme = ["dep:base64", "hyper/client", "dep:hyper-rustls", "dep:rcgen", "dep:ring", "dep:x509-parser", "dep:tokio-rustls", "dep:rustls-pemfile"]

[dependencies]
cruet = "0.13"
anyhow = { version = "1", optional = true }
cruet.workspace = true
anyhow = { workspace = true, optional = true }
async-compression = { version = "0.3", features = ["brotli", "deflate", "gzip", "tokio"], optional = true }
async-trait = "0.1"
base64 = { version = "0.13", optional = true }
async-trait.workspace = true
base64 = { workspace = true, optional = true }
bytes = "1"
cookie = { version = "0.16", features = ["percent-encode"], optional = true }
cookie = { workspace = true, features = ["percent-encode"], optional = true }
encoding_rs = { version = "0.8", optional = true }
enumflags2 = "0.7"
fastrand = "1.5"
enumflags2.workspace = true
fastrand.workspace = true
form_urlencoded = "1"
futures-util = { version = "0.3", default-features = false, features = ["io"] }
headers = "0.3"
http = "0.2"
hyper = { version = "0.14", features = ["stream", "server", "http1", "http2", "tcp", "client"] }
futures-util = { workspace = true, default-features = false, features = ["io"] }
headers.workspace = true
http.workspace = true
hyper = { workspace = true, features = ["stream", "server", "http1", "http2", "tcp", "client"] }
hyper-rustls = { version = "0.23", optional = true }
mime = "0.3"
mime_guess = "2"
mime.workspace = true
mime_guess.workspace = true
multer = "2"
multimap = { version = "0.8", features = ["serde"] }
once_cell = "1"
parking_lot = "0.12"
percent-encoding = "2"
pin-project-lite = { version = "0.2", optional = true }
multimap = { workspace = true, features = ["serde"] }
once_cell.workspace = true
parking_lot.workspace = true
percent-encoding.workspace = true
pin-project = { workspace = true, optional = true }
rcgen = { version = "0.9", optional = true }
regex = "1"
regex.workspace = true
ring = { version = "0.16", optional = true }
rustls-pemfile = { version = "1.0", optional = true }
salvo_macros = { version = "0.35.2", path = "../macros" }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["raw_value"] }
serde_urlencoded = { version = "0.7", optional = true }
salvo_macros = { workspace = true, path = "../macros" }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["raw_value"] }
serde_urlencoded = { workspace = true, optional = true }
tempfile = "3"
textnonce = "1"
thiserror = "1"
thiserror.workspace = true
openssl = { version = "0.10", optional = true }
tokio = { version = "1", features = ["fs", "rt-multi-thread"] }
tokio = { workspace = true, features = ["fs", "rt-multi-thread"] }
tokio-native-tls = { version = "0.3", optional = true }
tokio-rustls = { version = "0.23", optional = true }
tokio-openssl = { version = "0.6", optional = true }
tokio-stream = { version = "0.1", default-features = false }
tracing = "0.1"
url = { version = "2", optional = true }
tokio-stream = { workspace = true, default-features = false }
tracing.workspace = true
url = { workspace = true, optional = true }
x509-parser = { version = "0.14", optional = true }

[dev-dependencies]
reqwest = { version = "0.11", features = ["json"] }
reqwest = { workspace = true, features = ["json"] }
23 changes: 11 additions & 12 deletions crates/core/src/listener/native_tls.rs
Expand Up @@ -11,7 +11,7 @@ use futures_util::future::Ready;
use futures_util::{ready, stream, Stream};
use hyper::server::accept::Accept;
use hyper::server::conn::{AddrIncoming, AddrStream};
use pin_project_lite::pin_project;
use pin_project::pin_project;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio_native_tls::native_tls::{Identity, TlsAcceptor};
use tokio_native_tls::{TlsAcceptor as AsyncTlsAcceptor, TlsStream};
Expand Down Expand Up @@ -84,15 +84,14 @@ impl NativeTlsConfig {
}
}

pin_project! {
/// NativeTlsListener
#[pin_project]
pub struct NativeTlsListener<C> {
#[pin]
config_stream: C,
incoming: AddrIncoming,
identity: Option<Identity>,
}
}

/// NativeTlsListener
pub struct NativeTlsListenerBuilder<C> {
Expand Down Expand Up @@ -205,16 +204,16 @@ where
}
}

pin_project! {
/// NativeTlsStream
pub struct NativeTlsStream {
#[pin]
inner_future: Pin<Box<dyn Future<Output=Result<TlsStream<AddrStream>, tokio_native_tls::native_tls::Error>> + Send>>,
inner_stream: Option<TlsStream<AddrStream>>,
remote_addr: SocketAddr,
accepted: bool,
}
/// NativeTlsStream
#[pin_project]
pub struct NativeTlsStream {
#[pin]
inner_future: Pin<Box<dyn Future<Output=Result<TlsStream<AddrStream>, tokio_native_tls::native_tls::Error>> + Send>>,
inner_stream: Option<TlsStream<AddrStream>>,
remote_addr: SocketAddr,
accepted: bool,
}

impl Transport for NativeTlsStream {
#[inline]
fn remote_addr(&self) -> Option<SocketAddr> {
Expand Down
20 changes: 10 additions & 10 deletions crates/core/src/listener/openssl.rs
Expand Up @@ -14,7 +14,7 @@ use hyper::server::conn::{AddrIncoming, AddrStream};
use openssl::pkey::PKey;
use openssl::ssl::{Ssl, SslAcceptor, SslAcceptorBuilder, SslMethod, SslRef};
use openssl::x509::X509;
use pin_project_lite::pin_project;
use pin_project::pin_project;
use tokio::io::{AsyncRead, AsyncWrite, ErrorKind, ReadBuf};
use tokio_openssl::SslStream;

Expand Down Expand Up @@ -154,16 +154,16 @@ impl OpensslConfig {
}
}

pin_project! {
/// OpensslListener
pub struct OpensslListener<C> {
#[pin]
config_stream: C,
incoming: AddrIncoming,
openssl_config: Option<OpensslConfig>,
acceptor: Option<Arc<SslAcceptor>>,
}
/// OpensslListener
#[pin_project]
pub struct OpensslListener<C> {
#[pin]
config_stream: C,
incoming: AddrIncoming,
openssl_config: Option<OpensslConfig>,
acceptor: Option<Arc<SslAcceptor>>,
}

/// OpensslListener
pub struct OpensslListenerBuilder<C> {
config_stream: C,
Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/listener/rustls.rs
Expand Up @@ -13,7 +13,7 @@ use futures_util::future::Ready;
use futures_util::{ready, stream, Stream};
use hyper::server::accept::Accept;
use hyper::server::conn::{AddrIncoming, AddrStream};
use pin_project_lite::pin_project;
use pin_project::pin_project;
use tokio::io::{AsyncRead, AsyncWrite, ErrorKind, ReadBuf};
pub use tokio_rustls::rustls::server::ServerConfig;
use tokio_rustls::rustls::server::{
Expand Down Expand Up @@ -300,15 +300,15 @@ fn read_trust_anchor(mut trust_anchor: &[u8]) -> io::Result<RootCertStore> {
Ok(store)
}

pin_project! {
/// RustlsListener
#[pin_project]
pub struct RustlsListener<C> {
#[pin]
config_stream: C,
incoming: AddrIncoming,
server_config: Option<Arc<ServerConfig>>,
}
}

/// RustlsListener
pub struct RustlsListenerBuilder<C> {
config_stream: C,
Expand Down

0 comments on commit 8eb0ceb

Please sign in to comment.