index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2023-06-01 22:07:41.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2023-06-01 22:10:55.0 +00:00:00
commit
20de5d0b442b302111d5fce0e94866e3c23833db [patch]
tree
d0ba08cd29bc1ab592033b978025dc9c630bc15e
parent
4e01de60e7521fe6fe4c9eae5fcb00cf1988d6f5
download
20de5d0b442b302111d5fce0e94866e3c23833db.tar.gz

refactor: https redirect feature improvements



Diff

 src/lib.rs          |  1 +
 src/server.rs       | 33 ++++++++++++++++-----------------
 src/settings/cli.rs |  8 ++++----
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs
index 3fe8c44..950d0f1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -116,6 +116,7 @@ pub mod exts;
pub mod fallback_page;
pub mod handler;
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub mod https_redirect;
pub mod logger;
pub mod redirects;
diff --git a/src/server.rs b/src/server.rs
index f96b71a..93630b2 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -235,22 +235,6 @@ impl Server {
        let grace_period = general.grace_period;
        tracing::info!("grace period before graceful shutdown: {}s", grace_period);

        // HTTP to HTTPS redirect option
        let https_redirect = general.https_redirect;
        tracing::info!("http to https redirect: enabled={}", https_redirect);
        tracing::info!(
            "http to https redirect host: {}",
            general.https_redirect_host
        );
        tracing::info!(
            "http to https redirect from port: {}",
            general.https_redirect_from_port
        );
        tracing::info!(
            "http to https redirect from hosts: {}",
            general.https_redirect_from_hosts
        );

        // Create a service router for Hyper
        let router_service = RouterService::new(RequestHandler {
            opts: Arc::from(RequestHandlerOpts {
@@ -292,8 +276,23 @@ impl Server {
        // Run the corresponding HTTP Server asynchronously with its given options
        #[cfg(feature = "http2")]
        if general.http2 {
            // HTTP/2 + TLS
            // HTTP to HTTPS redirect option
            let https_redirect = general.https_redirect;
            tracing::info!("http to https redirect: enabled={}", https_redirect);
            tracing::info!(
                "http to https redirect host: {}",
                general.https_redirect_host
            );
            tracing::info!(
                "http to https redirect from port: {}",
                general.https_redirect_from_port
            );
            tracing::info!(
                "http to https redirect from hosts: {}",
                general.https_redirect_from_hosts
            );

            // HTTP/2 + TLS
            tcp_listener
                .set_nonblocking(true)
                .with_context(|| "failed to set TCP non-blocking mode")?;
diff --git a/src/settings/cli.rs b/src/settings/cli.rs
index fc41286..aa2b896 100644
--- a/src/settings/cli.rs
+++ b/src/settings/cli.rs
@@ -12,7 +12,7 @@ use crate::directory_listing::DirListFmt;

/// General server configuration available in CLI and config file options.
#[derive(Debug, StructOpt)]
#[structopt(about, author)]
#[structopt(about, author, version)]
pub struct General {
    #[structopt(long, short = 'a', default_value = "::", env = "SERVER_HOST")]
    /// Host address (E.g 127.0.0.1 or ::1)
@@ -176,7 +176,7 @@ pub struct General {
        long,
        requires_if("true", "https-redirect"),
        default_value = "localhost",
        env = "HTTPS_REDIRECT_HOST"
        env = "SERVER_HTTPS_REDIRECT_HOST"
    )]
    #[cfg(feature = "http2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
@@ -187,7 +187,7 @@ pub struct General {
        long,
        requires_if("true", "https-redirect"),
        default_value = "80",
        env = "HTTPS_REDIRECT_FROM_PORT"
        env = "SERVER_HTTPS_REDIRECT_FROM_PORT"
    )]
    #[cfg(feature = "http2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
@@ -198,7 +198,7 @@ pub struct General {
        long,
        requires_if("true", "https-redirect"),
        default_value = "localhost",
        env = "HTTPS_REDIRECT_FROM_HOSTS"
        env = "SERVER_HTTPS_REDIRECT_FROM_HOSTS"
    )]
    #[cfg(feature = "http2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "http2")))]