Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server feature #576

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: cargo install cargo-hack

- name: check --feature-powerset
run: cargo hack check --feature-powerset --depth 1 -Z avoid-dev-deps
run: cargo hack check --feature-powerset --depth 1 -Z avoid-dev-deps --exclude-features server

cover:
strategy:
Expand Down
7 changes: 4 additions & 3 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["cookie", "http1", "fix-http1-request-uri", "http2", "test"]
full = ["cookie", "http1", "fix-http1-request-uri", "http2", "quinn", "rustls", "native-tls", "openssl", "unix", "test", "tower-compat", "anyhow", "eyre"]
default = ["cookie", "fix-http1-request-uri", "server", "http1", "http2"]
full = ["cookie", "fix-http1-request-uri", "server", "http1", "http2", "quinn", "rustls", "native-tls", "openssl", "unix", "test", "tower-compat", "anyhow", "eyre"]
cookie = ["dep:cookie"]
http1 = []
fix-http1-request-uri = ["http1"]
server = []
http1 = []
http2 = ["hyper/http2"]
quinn = ["dep:salvo-http3", "dep:quinn", "dep:tokio-rustls-old", "dep:rustls-pemfile-old", "rustls"]
rustls = ["http1", "http2", "dep:tokio-rustls", "dep:rustls-pemfile"]
Expand Down
12 changes: 9 additions & 3 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ pub mod routing;
pub mod rt;
#[doc(hidden)]
pub mod serde;
pub mod server;
cfg_feature! {
#![feature ="server"]
pub mod server;
pub use self::server::Server;
}
mod service;
pub mod writing;
cfg_feature! {
Expand All @@ -57,7 +61,6 @@ pub use self::extract::Extractible;
pub use self::handler::Handler;
pub use self::http::{Request, Response};
pub use self::routing::{FlowCtrl, Router};
pub use self::server::Server;
pub use self::service::Service;
pub use self::writing::{Scribe, Writer};
/// Result type which has `salvo::Error` as it's error type.
Expand Down Expand Up @@ -101,7 +104,10 @@ pub mod prelude {
pub use crate::conn::{JoinedListener, Listener, TcpListener};
pub use crate::handler::{self, Handler};
pub use crate::routing::{FlowCtrl, Router};
pub use crate::server::Server;
cfg_feature! {
#![feature = "server"]
pub use crate::server::Server;
}
pub use crate::service::Service;
pub use crate::writing::{Json, Redirect, Scribe, Text, Writer};
}
Expand Down
3 changes: 3 additions & 0 deletions crates/core/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use std::io::Result as IoResult;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

#[cfg(not(any(feature = "http1", feature = "http2", feature = "quinn")))]
compile_error!("You have enabled `server` feature, it requires at least one of the following features: http1, http2, quinn.");

#[cfg(feature = "http1")]
use hyper::server::conn::http1;
#[cfg(feature = "http2")]
Expand Down
1 change: 0 additions & 1 deletion crates/oapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ mime-infer = { workspace = true }
once_cell = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_urlencoded = { workspace = true }
regex = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions crates/salvo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ name = "salvo"
path = "src/lib.rs"

[features]
default = ["cookie", "http1", "fix-http1-request-uri", "http2", "test"]
full = ["cookie", "http1", "fix-http1-request-uri", "http2", "quinn", "rustls", "native-tls", "openssl", "unix", "acme", "tower-compat", "anyhow", "eyre", "test", "affix", "basic-auth", "force-https", "jwt-auth", "catch-panic", "compression", "logging", "proxy", "concurrency-limiter", "rate-limiter", "sse", "trailing-slash", "timeout", "websocket", "request-id", "caching-headers", "cache", "cors", "csrf", "flash", "rate-limiter", "session", "serve-static", "otel", "oapi"]
default = ["cookie", "fix-http1-request-uri", "server", "http1", "http2"]
full = ["cookie", "fix-http1-request-uri", "server", "http1", "http2", "quinn", "rustls", "native-tls", "openssl", "unix", "acme", "tower-compat", "anyhow", "eyre", "test", "affix", "basic-auth", "force-https", "jwt-auth", "catch-panic", "compression", "logging", "proxy", "concurrency-limiter", "rate-limiter", "sse", "trailing-slash", "timeout", "websocket", "request-id", "caching-headers", "cache", "cors", "csrf", "flash", "rate-limiter", "session", "serve-static", "otel", "oapi"]
cookie = ["salvo_core/cookie"]
http1 = ["salvo_core/http1"]
fix-http1-request-uri = ["salvo_core/fix-http1-request-uri"]
server = ["salvo_core/server"]
http1 = ["salvo_core/http1"]
http2 = ["salvo_core/http2"]
quinn = ["salvo_core/quinn"]
rustls = ["salvo_core/rustls"]
Expand Down