diff options
author | Alex Auvolat <alex@adnab.me> | 2021-12-09 15:43:19 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-12-09 15:43:19 +0100 |
commit | 9b30f2b7d17cbee39c271d159524202e0ffa297c (patch) | |
tree | 4f523a832ab3e18e87241c1e3f2d28d5a332f180 /src/main.rs | |
parent | e4942490ee6f51573223772ceee8a8ac46b55ae6 (diff) | |
download | tricot-9b30f2b7d17cbee39c271d159524202e0ffa297c.tar.gz tricot-9b30f2b7d17cbee39c271d159524202e0ffa297c.zip |
Compression
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index 61fc747..febe540 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,18 @@ struct Opt { /// E-mail address for Let's Encrypt certificate requests #[structopt(long = "letsencrypt-email", env = "TRICOT_LETSENCRYPT_EMAIL")] pub letsencrypt_email: String, + + /// Enable compression of responses + #[structopt(long = "enable-compression", env = "TRICOT_ENABLE_COMPRESSION")] + pub enable_compression: bool, + + /// Mime types for which to enable compression (comma-separated list) + #[structopt( + long = "compress-mime-types", + env = "TRICOT_COMPRESS_MIME_TYPES", + default_value = "text/html,text/plain,text/css,text/javascript,application/javascript,image/svg+xml" + )] + pub compress_mime_types: String, } #[tokio::main(flavor = "multi_thread", worker_threads = 10)] @@ -87,13 +99,19 @@ async fn main() { ); tokio::spawn(http::serve_http(opt.http_bind_addr, consul.clone()).map_err(exit_on_err)); + + let https_config = https::HttpsConfig { + bind_addr: opt.https_bind_addr, + enable_compression: opt.enable_compression, + compress_mime_types: opt + .compress_mime_types + .split(",") + .map(|x| x.to_string()) + .collect(), + }; tokio::spawn( - https::serve_https( - opt.https_bind_addr, - cert_store.clone(), - rx_proxy_config.clone(), - ) - .map_err(exit_on_err), + https::serve_https(https_config, cert_store.clone(), rx_proxy_config.clone()) + .map_err(exit_on_err), ); while rx_proxy_config.changed().await.is_ok() { |