diff options
author | Andy Kurnia <andy-k@users.noreply.github.com> | 2022-05-13 20:10:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-13 14:10:05 +0200 |
commit | 42fec5150ecbd80f110d2bb32f1dcd2b2a344dd3 (patch) | |
tree | 414d12de7ae1b9776a7a5ab2fa6245be7d19631f /ext/http/lib.rs | |
parent | eed7afc3aa07f52668c99f608d044e2f1902cca8 (diff) |
fix(ext/http): make serveHttp compress for Accept-Encoding: deflate, gzip (#14525)
Diffstat (limited to 'ext/http/lib.rs')
-rw-r--r-- | ext/http/lib.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/ext/http/lib.rs b/ext/http/lib.rs index d1d884457..edc4c1e83 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -392,10 +392,28 @@ async fn op_http_accept( { let mut accept_encoding = stream.accept_encoding.borrow_mut(); - *accept_encoding = fly_accept_encoding::parse(request.headers()) - .ok() - .flatten() - .unwrap_or(Encoding::Identity); + + // curl --compressed sends "Accept-Encoding: deflate, gzip". + // fly_accept_encoding::parse() returns Encoding::Deflate. + // Deno does not support Encoding::Deflate. + // So, Deno used no compression, although gzip was possible. + // This patch makes Deno use gzip instead in this case. + *accept_encoding = Encoding::Identity; + let mut max_qval = 0.0; + if let Ok(encodings) = fly_accept_encoding::encodings(request.headers()) { + for (encoding, qval) in encodings { + if let Some(enc @ (Encoding::Brotli | Encoding::Gzip)) = encoding { + // this logic came from fly_accept_encoding. + if (qval - 1.0f32).abs() < 0.01 { + *accept_encoding = enc; + break; + } else if qval > max_qval { + *accept_encoding = enc; + max_qval = qval; + } + } + } + } } let method = request.method().to_string(); |