refactor: drop support for deflate in favor of gzip
since gzip is deflate with extra headers and checksum
Diff
README.md | 6 +++---
src/config.rs | 2 +-
src/server.rs | 54 +-----------------------------------------------------
3 files changed, 5 insertions(+), 57 deletions(-)
@@ -13,7 +13,7 @@ For stable `v1` and contributions please refer to [1.x](https://github.com/josel
- Memory safety and very reduced CPU and RAM overhead.
- Blazing fast static files-serving and asynchronous powered by [Warp](https://github.com/seanmonstar/warp/) `v0.3` ([Hyper](https://github.com/hyperium/hyper/) `v0.14`), [Tokio](https://github.com/tokio-rs/tokio) `v1` and a set of [awesome crates](./Cargo.toml).
- Suitable for lightweight [GNU/Linux Docker containers](https://hub.docker.com/r/joseluisq/static-web-server/tags). It's a fully __5MB__ static binary thanks to [Rust and Musl libc](https://doc.rust-lang.org/edition-guide/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html).
- Opt-in GZip, Deflate or Brotli compression for text-based web files only.
- Opt-in GZip or Brotli compression for text-based web files only.
- Compression on demand via [Accept-Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding) header.
- [Partial Content Delivery](https://en.wikipedia.org/wiki/Byte_serving) support for byte-serving of large files.
- [Cache Control](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) headers for assets.
@@ -49,7 +49,7 @@ Server can be configured either via environment variables or their equivalent co
@@ -73,7 +73,7 @@ FLAGS:
OPTIONS:
-x, --compression <compression>
Compression body support for web text-based file types. Values: "gzip", "deflate" or "brotli". Use an empty
Compression body support for web text-based file types. Values: "gzip" or "brotli". Use an empty
value to skip compression [env: SERVER_COMPRESSION=] [default: gzip]
-c, --cors-allow-origins <cors-allow-origins>
Specify a optional CORS list of allowed origin hosts separated by comas. Host ports or protocols aren't
@@ -44,7 +44,7 @@ pub struct Config {
pub page404: String,
#[structopt(long, short = "x", default_value = "gzip", env = "SERVER_COMPRESSION")]
pub compression: String,
@@ -80,7 +80,7 @@ impl Server {
let http2_tls_cert_path = opts.http2_tls_cert;
let http2_tls_key_path = opts.http2_tls_key;
match opts.compression.as_ref() {
"brotli" => tokio::task::spawn(async move {
let with_dir = warp::fs::dir(root_dir)
@@ -134,58 +134,6 @@ impl Server {
}
}
}),
"deflate" => tokio::task::spawn(async move {
let with_dir = warp::fs::dir(root_dir)
.map(cache::control_headers)
.with(warp::trace::request())
.with(warp::compression::deflate(true))
.recover(move |rej| {
let page404 = page404.clone();
let page50x = page50x.clone();
async move { rejection::handle_rejection(page404, page50x, rej).await }
});
if let Some(cors_filter) = cors_filter {
tracing::info!(
cors_enabled = ?true,
allowed_origins = ?cors_allowed_origins
);
let server = warp::serve(
public_head.with(cors_filter.clone()).or(warp::get()
.and(filters::has_accept_encoding("deflate"))
.and(with_dir)
.with(cors_filter.clone())
.or(public_get_default.with(cors_filter))),
);
if http2 {
server
.tls()
.cert_path(http2_tls_cert_path)
.key_path(http2_tls_key_path)
.run(addr)
.await;
} else {
server.run(addr).await
}
} else {
let server = warp::serve(
public_head.or(warp::get()
.and(filters::has_accept_encoding("deflate"))
.and(with_dir)
.or(public_get_default)),
);
if http2 {
server
.tls()
.cert_path(http2_tls_cert_path)
.key_path(http2_tls_key_path)
.run(addr)
.await;
} else {
server.run(addr).await
}
}
}),
"gzip" => tokio::task::spawn(async move {
let with_dir = warp::fs::dir(root_dir)
.map(cache::control_headers)