index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2021-01-07 2:31:16.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2021-01-07 2:31:16.0 +00:00:00
commit
63bf60d1c215f506bb1cec6df5e360fbfe450eee [patch]
tree
5e51013230bfbebe98b7860635bcb54f96fe2824
parent
bbe6ed8bc2b39da45394ab0203e6dc13739a5eb5
download
63bf60d1c215f506bb1cec6df5e360fbfe450eee.tar.gz

feat: head http responses support



Diff

 Cargo.lock        |  3 +--
 Cargo.toml        |  2 +-
 src/bin/server.rs | 18 ++++++++++++------
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 53c8e39..a4fb8f5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1692,8 +1692,7 @@ dependencies = [
[[package]]
name = "warp"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f41be6df54c97904af01aa23e613d4521eed7ab23537cede692d4058f6449407"
source = "git+https://github.com/joseluisq/warp.git?branch=0.2.x#1865f785faf9bde73f0dc2b1b0778c42aee829b9"
dependencies = [
 "async-compression",
 "bytes",
diff --git a/Cargo.toml b/Cargo.toml
index b1d206a..a8cf4a8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,7 +22,7 @@ include = ["src/**/*", "Cargo.toml", "Cargo.lock"]

[dependencies]
tokio = { version = "0.2", features = ["full"] }
warp = { version = "0.2", features = ["compression"] }
warp = { git = "https://github.com/joseluisq/warp.git", branch = "0.2.x", features = ["compression"] }
anyhow = "1.0"
tracing = "0.1"
tracing-subscriber = "0.2"
diff --git a/src/bin/server.rs b/src/bin/server.rs
index 6254d82..616b326 100644
--- a/src/bin/server.rs
+++ b/src/bin/server.rs
@@ -16,16 +16,22 @@ use self::static_web_server::core::*;
async fn server(opts: config::Options) -> Result {
    logger::init(&opts.log_level)?;

    let filters = warp::get()
        .and(warp::fs::dir(opts.root))
        .with(warp::compression::gzip())
        .recover(rejection::handle_rejection)
        .with(warp::trace::request());
    let public_head = warp::head().and(warp::fs::dir(opts.root.clone()));
    let public_get = warp::get().and(warp::fs::dir(opts.root));

    let routes = public_head.or(public_get.with(warp::compression::gzip()));

    let host = opts.host.parse::<std::net::IpAddr>()?;
    let port = opts.port;

    tokio::task::spawn(warp::serve(filters).run((host, port)));
    tokio::task::spawn(
        warp::serve(
            routes
                .with(warp::trace::request())
                .recover(rejection::handle_rejection),
        )
        .run((host, port)),
    );

    signals::wait(|sig: signals::Signal| {
        let code = signals::as_int(sig);