mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
feat(ext/http): option to disable auto-compression
This commit is contained in:
parent
d8827514ff
commit
397cd3f6db
5 changed files with 16 additions and 6 deletions
|
@ -70,7 +70,9 @@ use tokio_util::io::ReaderStream;
|
||||||
|
|
||||||
pub mod compressible;
|
pub mod compressible;
|
||||||
|
|
||||||
pub fn init() -> Extension {
|
pub struct AutoCompression(bool);
|
||||||
|
|
||||||
|
pub fn init(auto_compression: bool) -> Extension {
|
||||||
Extension::builder()
|
Extension::builder()
|
||||||
.js(include_js_files!(
|
.js(include_js_files!(
|
||||||
prefix "deno:ext/http",
|
prefix "deno:ext/http",
|
||||||
|
@ -87,6 +89,12 @@ pub fn init() -> Extension {
|
||||||
op_http_websocket_accept_header::decl(),
|
op_http_websocket_accept_header::decl(),
|
||||||
op_http_upgrade_websocket::decl(),
|
op_http_upgrade_websocket::decl(),
|
||||||
])
|
])
|
||||||
|
.state(move |state| {
|
||||||
|
if auto_compression {
|
||||||
|
state.put(AutoCompression(auto_compression));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -490,6 +498,7 @@ async fn op_http_write_headers(
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.resource_table
|
.resource_table
|
||||||
.get::<HttpStreamResource>(rid)?;
|
.get::<HttpStreamResource>(rid)?;
|
||||||
|
let auto_compression = state.borrow().borrow::<AutoCompression>().0;
|
||||||
|
|
||||||
// Track supported encoding
|
// Track supported encoding
|
||||||
let encoding = stream.accept_encoding;
|
let encoding = stream.accept_encoding;
|
||||||
|
@ -511,7 +520,8 @@ async fn op_http_write_headers(
|
||||||
|
|
||||||
let accepts_compression =
|
let accepts_compression =
|
||||||
matches!(encoding, Encoding::Brotli | Encoding::Gzip);
|
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())
|
&& (matches!(data, Some(ref data) if data.len() > 20) || data.is_none())
|
||||||
&& should_compress(hmap);
|
&& should_compress(hmap);
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,7 @@ mod not_docs {
|
||||||
None, false, // No --unstable.
|
None, false, // No --unstable.
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
deno_http::init(),
|
deno_http::init(true),
|
||||||
deno_flash::init::<Permissions>(false), // No --unstable
|
deno_flash::init::<Permissions>(false), // No --unstable
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -438,7 +438,7 @@ impl WebWorker {
|
||||||
ops::spawn::init(),
|
ops::spawn::init(),
|
||||||
ops::signal::init(),
|
ops::signal::init(),
|
||||||
ops::tty::init(),
|
ops::tty::init(),
|
||||||
deno_http::init(),
|
deno_http::init(true),
|
||||||
deno_flash::init::<Permissions>(unstable),
|
deno_flash::init::<Permissions>(unstable),
|
||||||
ops::http::init(),
|
ops::http::init(),
|
||||||
// Permissions ext (worker specific state)
|
// Permissions ext (worker specific state)
|
||||||
|
|
|
@ -195,7 +195,7 @@ impl MainWorker {
|
||||||
ops::process::init(),
|
ops::process::init(),
|
||||||
ops::signal::init(),
|
ops::signal::init(),
|
||||||
ops::tty::init(),
|
ops::tty::init(),
|
||||||
deno_http::init(),
|
deno_http::init(true),
|
||||||
deno_flash::init::<Permissions>(unstable),
|
deno_flash::init::<Permissions>(unstable),
|
||||||
ops::http::init(),
|
ops::http::init(),
|
||||||
// Permissions ext (worker specific state)
|
// Permissions ext (worker specific state)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9f314cefb507e3b9de08edc6046353e4012279fc
|
Subproject commit 17fd391b8f305d1e74ce7508c824176f09ab63d0
|
Loading…
Reference in a new issue