diff --git a/Cargo.lock b/Cargo.lock index 4f5aaaf..b1307d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9419,6 +9419,7 @@ version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" dependencies = [ + "async-compression", "bitflags 2.10.0", "bytes", "futures-core", diff --git a/htmlshell/Cargo.toml b/htmlshell/Cargo.toml index 86bd84c..e40489e 100644 --- a/htmlshell/Cargo.toml +++ b/htmlshell/Cargo.toml @@ -46,7 +46,7 @@ servo_config = { path = "../source/components/config" } servo_config_macro = { path = "../source/components/config/macro" } tokio = { workspace = true } tower = "0.5" -tower-http = { version = "0.6", features = ["cors", "fs"] } +tower-http = { version = "0.6", features = ["async-compression", "compression-zstd", "cors", "fs"] } tracing = { workspace = true, optional = true } tracing-perfetto = { workspace = true, optional = true } tracing-subscriber = { workspace = true, optional = true, features = ["env-filter"] } diff --git a/htmlshell/src/vhost.rs b/htmlshell/src/vhost.rs index a8d5363..7eca5a9 100644 --- a/htmlshell/src/vhost.rs +++ b/htmlshell/src/vhost.rs @@ -13,6 +13,7 @@ use log::error; use parking_lot::Mutex; use servo::prefs::{PreferencesObserver, get_embedder_pref}; use servo::{PrefValue, prefs}; +use tower_http::compression::CompressionLayer; use tower_http::cors::{Any, CorsLayer}; use tower_http::services::ServeFile; use tower_http::services::fs::ServeFileSystemResponseBody; @@ -49,12 +50,12 @@ fn vhost_handler(state: ServerState, request: Request) -> Option { // Currently recognized: system, shared, keyboard, homescreen, theme // TODO: don't hardcode - if app != "homescreen" && - app != "keyboard" && - app != "settings" && - app != "shared" && - app != "system" && - app != "theme" + if app != "homescreen" + && app != "keyboard" + && app != "settings" + && app != "shared" + && app != "system" + && app != "theme" { return None; } @@ -141,9 +142,13 @@ pub(crate) fn start_vhost(port: u16) { .allow_methods(Any) .allow_headers(Any); + let compression = CompressionLayer::new() + .zstd(true); + let app = Router::new() .route("/{*key}", get(get_file)) .layer(cors) + .layer(compression) .with_state(state); servo::Servo::spawn_task(async move {