Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit 1c8e572

Browse files
committed
use fastest compression encoding
1 parent 74101ae commit 1c8e572

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/http_compression.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::io::Result;
22
use std::ops::Deref;
33

4+
use async_compression::Level;
45
use async_compression::tokio::write::{BrotliDecoder, BrotliEncoder, DeflateDecoder, DeflateEncoder, GzipDecoder, GzipEncoder};
56
use bytes::Bytes;
7+
use Level::Fastest;
68
use tokio::io::AsyncWriteExt;
79

810
pub async fn decompress(bytes: Bytes, algorithm: Algorithm) -> Result<Bytes> {
@@ -31,19 +33,19 @@ pub async fn decompress(bytes: Bytes, algorithm: Algorithm) -> Result<Bytes> {
3133
pub async fn compress(bytes: Bytes, algorithm: Algorithm) -> Result<Bytes> {
3234
match algorithm {
3335
Algorithm::Brotli => {
34-
let mut encoder = BrotliEncoder::new(Vec::new());
36+
let mut encoder = BrotliEncoder::with_quality(Vec::new(), Fastest);
3537
encoder.write_all(bytes.deref()).await?;
3638
encoder.shutdown().await?;
3739
Ok(Bytes::from(encoder.into_inner()))
3840
}
3941
Algorithm::Gzip => {
40-
let mut encoder = GzipEncoder::new(Vec::new());
42+
let mut encoder = GzipEncoder::with_quality(Vec::new(), Fastest);
4143
encoder.write_all(bytes.deref()).await?;
4244
encoder.shutdown().await?;
4345
Ok(Bytes::from(encoder.into_inner()))
4446
}
4547
Algorithm::Deflate => {
46-
let mut encoder = DeflateEncoder::new(Vec::new());
48+
let mut encoder = DeflateEncoder::with_quality(Vec::new(), Fastest);
4749
encoder.write_all(bytes.deref()).await?;
4850
encoder.shutdown().await?;
4951
Ok(Bytes::from(encoder.into_inner()))

src/routes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ pub async fn routes() {
1818
.map(move |_id, _page| (config.upstream_url.clone(), "".to_string()))
1919
.untuple_one()
2020
.and(extract_request_data_filter())
21-
.and_then(proxy_upscale_and_forward)
22-
.with(warp::compression::brotli());
21+
.and_then(proxy_upscale_and_forward);
2322

2423
let kavita_upscale = warp::path!("api"/"reader"/"image")
2524
.map(|| (config.upstream_url.clone(), "".to_string()))
@@ -50,6 +49,7 @@ async fn proxy_upscale_and_forward(
5049
body: Bytes,
5150
) -> Result<Response<Bytes>, Rejection> {
5251
let uri_str = format!("{} {}", method, uri.as_str());
52+
// TODO do not request compressed data to avoid decode and re-encode
5353
let response = proxy_to_and_forward_response(proxy_address, base_path, uri, params, method, headers, body).await?;
5454
let status = response.status();
5555

0 commit comments

Comments
 (0)