From 6b81c48314dd48d1daa7de7f6c6a3210f3ff2b5f Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Mon, 8 May 2023 02:21:22 +0200 Subject: [PATCH] refactor: simplify http2 cargo feature it removes the `tls` cargo feature for consistency because http2 can not leave without tls in practice. https://stackoverflow.com/a/46789195/2510591 ref: #182 --- Cargo.toml | 3 +-- docs/content/building-from-source.md | 1 - src/lib.rs | 5 ++--- src/server.rs | 12 +++++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cbc68fa..c46273f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,8 +40,7 @@ doc = false [features] default = ["compression", "http2"] # HTTP2 -tls = ["tokio-rustls", "rustls-pemfile"] -http2 = ["tls"] +http2 = ["tokio-rustls", "rustls-pemfile"] # Compression compression = ["compression-brotli", "compression-deflate", "compression-gzip", "compression-zstd"] compression-brotli = ["async-compression/brotli"] diff --git a/docs/content/building-from-source.md b/docs/content/building-from-source.md index ee29f7f..2556819 100644 --- a/docs/content/building-from-source.md +++ b/docs/content/building-from-source.md @@ -32,7 +32,6 @@ Feature | Description `default` | Activates all features by default. [**HTTP2/TLS**](./features/http2-tls.md) | `http2` | Activates the HTTP2 and TLS feature. -`tls` | Activates only the TLS feature. [**Compression**](./features/compression.md) | `compression` | Activates auto-compression and compression static with all supported algorithms. `compression-brotli` | Activates auto-compression/compression static with only the `brotli` algorithm. diff --git a/src/lib.rs b/src/lib.rs index 936f02c..d8c59d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,7 +78,6 @@ //! `default` | Activates all features by default. //! [**HTTP2/TLS**](https://static-web-server.net/features/http2-tls/) | //! `http2` | Activates the HTTP2 and TLS feature. -//! `tls` | Activates only the TLS feature. //! [**Compression**](https://static-web-server.net/features/compression/) | //! `compression` | Activates auto-compression and compression static with all supported algorithms. //! `compression-brotli` | Activates auto-compression/compression static with only the `brotli` algorithm. @@ -126,8 +125,8 @@ pub mod settings; #[cfg(any(unix, windows))] pub mod signals; pub mod static_files; -#[cfg(feature = "tls")] -#[cfg_attr(docsrs, doc(cfg(feature = "tls")))] +#[cfg(feature = "http2")] +#[cfg_attr(docsrs, doc(cfg(feature = "http2")))] pub mod tls; pub mod transport; #[cfg(windows)] diff --git a/src/server.rs b/src/server.rs index cb792a3..a2a9915 100644 --- a/src/server.rs +++ b/src/server.rs @@ -6,9 +6,6 @@ //! Server module intended to construct a multi-thread HTTP or HTTP/2 web server. //! -#[allow(unused_imports)] -use hyper::server::conn::AddrIncoming; -#[allow(unused_imports)] use hyper::server::Server as HyperServer; use listenfd::ListenFd; use std::net::{IpAddr, SocketAddr, TcpListener}; @@ -18,8 +15,13 @@ use tokio::sync::oneshot::Receiver; use crate::handler::{RequestHandler, RequestHandlerOpts}; #[cfg(any(unix, windows))] use crate::signals; -#[cfg(feature = "tls")] -use crate::tls::{TlsAcceptor, TlsConfigBuilder}; + +#[cfg(feature = "http2")] +use { + crate::tls::{TlsAcceptor, TlsConfigBuilder}, + hyper::server::conn::AddrIncoming, +}; + use crate::{cors, helpers, logger, Settings}; use crate::{service::RouterService, Context, Result}; -- libgit2 1.7.2