From 397cd3f6db2ca43ae8629036d01f5cb6ed4c48bd Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Mon, 24 Oct 2022 19:50:24 +0400 Subject: [PATCH] feat(ext/http): option to disable auto-compression --- ext/http/lib.rs | 14 ++++++++++++-- runtime/build.rs | 2 +- runtime/web_worker.rs | 2 +- runtime/worker.rs | 2 +- third_party | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ext/http/lib.rs b/ext/http/lib.rs index d1b38fb42d..174e3129d8 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -70,7 +70,9 @@ use tokio_util::io::ReaderStream; pub mod compressible; -pub fn init() -> Extension { +pub struct AutoCompression(bool); + +pub fn init(auto_compression: bool) -> Extension { Extension::builder() .js(include_js_files!( prefix "deno:ext/http", @@ -87,6 +89,12 @@ pub fn init() -> Extension { op_http_websocket_accept_header::decl(), op_http_upgrade_websocket::decl(), ]) + .state(move |state| { + if auto_compression { + state.put(AutoCompression(auto_compression)); + } + Ok(()) + }) .build() } @@ -490,6 +498,7 @@ async fn op_http_write_headers( .borrow_mut() .resource_table .get::(rid)?; + let auto_compression = state.borrow().borrow::().0; // Track supported encoding let encoding = stream.accept_encoding; @@ -511,7 +520,8 @@ async fn op_http_write_headers( let accepts_compression = matches!(encoding, Encoding::Brotli | Encoding::Gzip); - let compressing = accepts_compression + let compressing = auto_compression + && accepts_compression && (matches!(data, Some(ref data) if data.len() > 20) || data.is_none()) && should_compress(hmap); diff --git a/runtime/build.rs b/runtime/build.rs index 55a89fb8bd..d67962c523 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -191,7 +191,7 @@ mod not_docs { None, false, // No --unstable. None, ), - deno_http::init(), + deno_http::init(true), deno_flash::init::(false), // No --unstable ]; diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 09a631916b..2b7c24c436 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -438,7 +438,7 @@ impl WebWorker { ops::spawn::init(), ops::signal::init(), ops::tty::init(), - deno_http::init(), + deno_http::init(true), deno_flash::init::(unstable), ops::http::init(), // Permissions ext (worker specific state) diff --git a/runtime/worker.rs b/runtime/worker.rs index 3ac3654e2e..7a5cb4501a 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -195,7 +195,7 @@ impl MainWorker { ops::process::init(), ops::signal::init(), ops::tty::init(), - deno_http::init(), + deno_http::init(true), deno_flash::init::(unstable), ops::http::init(), // Permissions ext (worker specific state) diff --git a/third_party b/third_party index 9f314cefb5..17fd391b8f 160000 --- a/third_party +++ b/third_party @@ -1 +1 @@ -Subproject commit 9f314cefb507e3b9de08edc6046353e4012279fc +Subproject commit 17fd391b8f305d1e74ce7508c824176f09ab63d0