From 9151fc13daaf5c2535c2708ec81d69fe6a234ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabrice=20Desr=C3=A9?= Date: Tue, 27 Sep 2022 05:01:46 -0700 Subject: [PATCH] feat: Enable the CompressionLayer middleware (#236) --- iroh-gateway/Cargo.toml | 2 +- iroh-gateway/src/handlers.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iroh-gateway/Cargo.toml b/iroh-gateway/Cargo.toml index 38e205aae0..bc52bf470b 100644 --- a/iroh-gateway/Cargo.toml +++ b/iroh-gateway/Cargo.toml @@ -40,7 +40,7 @@ iroh-resolver = { path = "../iroh-resolver" } tokio-util = { version = "0.7", features = ["io"] } bytes = "1.1.0" tower-layer = { version = "0.3" } -tower-http = { version = "0.3", features = ["trace"] } +tower-http = { version = "0.3", features = ["trace", "compression-full"] } http = "0.2" async-recursion = "1.0.0" handlebars = "4" diff --git a/iroh-gateway/src/handlers.rs b/iroh-gateway/src/handlers.rs index 1ca5c4361b..9e7481a54b 100644 --- a/iroh-gateway/src/handlers.rs +++ b/iroh-gateway/src/handlers.rs @@ -30,7 +30,7 @@ use std::{ time::{self, Duration}, }; use tower::ServiceBuilder; -use tower_http::trace::TraceLayer; +use tower_http::{compression::CompressionLayer, trace::TraceLayer}; use tracing::info_span; use url::Url; use urlencoding::encode; @@ -65,6 +65,7 @@ pub fn get_app_routes(state: &Arc) -> Router { ServiceBuilder::new() // Handle errors from middleware .layer(Extension(Arc::clone(state))) + .layer(CompressionLayer::new()) .layer(HandleErrorLayer::new(middleware_error_handler)) .load_shed() .concurrency_limit(2048)