From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 57F221FF2AB
	for <inbox@lore.proxmox.com>; Wed, 17 Jul 2024 17:49:06 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id A36A13ECF9;
	Wed, 17 Jul 2024 17:49:36 +0200 (CEST)
Mime-Version: 1.0
Date: Wed, 17 Jul 2024 17:49:33 +0200
Message-Id: <D2RXLKPZQ21G.BD38U6XFYQRY@proxmox.com>
To: "Proxmox Backup Server development discussion"
 <pbs-devel@lists.proxmox.com>
From: "Max Carrara" <m.carrara@proxmox.com>
X-Mailer: aerc 0.17.0-72-g6a84f1331f1c
References: <20240716092247.212133-1-m.sandoval@proxmox.com>
In-Reply-To: <20240716092247.212133-1-m.sandoval@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.029 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [rest.rs, rfc-editor.org]
Subject: Re: [pbs-devel] [PATCH proxmox] rest-server: Encode with zlib
 headers
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

On Tue Jul 16, 2024 at 11:22 AM CEST, Maximiliano Sandoval wrote:
> As per [RFC9110] the Deflate encoding is a "zlib" data format. This
> makes the rest-server compatible with the http-client.
>
> [RFC9110] https://www.rfc-editor.org/rfc/rfc9110#field.content-encoding
>
> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> ---
>
> By default the builder will use the default compression level. Please let me
> know if the Level::Default should be set explicitly.

This patch looks simple enough to me and does what it says on the tin;
I can't really spot anything wrong here.

Regarding your comment: I think the default level is perfectly fine.
Of course, one could be pedantic and try to benchmark any differences
between the levels, but IMHO that's rather redundant - if there are any
potential gains here, they're most likely miniscule.

In other words: LGTM.

Reviewed-by: Max Carrara <m.carrara@proxmox.com>

>
>  proxmox-rest-server/src/rest.rs | 35 ++++++++++++++++++---------------
>  1 file changed, 19 insertions(+), 16 deletions(-)
>
> diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs
> index 3a3c287c..4be36074 100644
> --- a/proxmox-rest-server/src/rest.rs
> +++ b/proxmox-rest-server/src/rest.rs
> @@ -30,7 +30,7 @@ use proxmox_router::{http_bail, http_err};
>  use proxmox_schema::{ObjectSchemaType, ParameterSchema};
>  
>  use proxmox_async::stream::AsyncReaderStream;
> -use proxmox_compression::{DeflateEncoder, Level};
> +use proxmox_compression::DeflateEncoder;
>  use proxmox_log::FileLogger;
>  
>  use crate::{
> @@ -557,12 +557,13 @@ pub(crate) async fn handle_api_request<Env: RpcEnvironment, S: 'static + BuildHa
>                  CompressionMethod::Deflate.content_encoding(),
>              );
>              resp.map(|body| {
> -                Body::wrap_stream(DeflateEncoder::with_quality(
> -                    TryStreamExt::map_err(body, |err| {
> +                Body::wrap_stream(
> +                    DeflateEncoder::builder(TryStreamExt::map_err(body, |err| {
>                          proxmox_lang::io_format_err!("error during compression: {}", err)
> -                    }),
> -                    Level::Default,
> -                ))
> +                    }))
> +                    .zlib(true)
> +                    .build(),
> +                )
>              })
>          }
>          None => resp,
> @@ -651,12 +652,13 @@ async fn handle_unformatted_api_request<Env: RpcEnvironment, S: 'static + BuildH
>                  CompressionMethod::Deflate.content_encoding(),
>              );
>              resp.map(|body| {
> -                Body::wrap_stream(DeflateEncoder::with_quality(
> -                    TryStreamExt::map_err(body, |err| {
> +                Body::wrap_stream(
> +                    DeflateEncoder::builder(TryStreamExt::map_err(body, |err| {
>                          proxmox_lang::io_format_err!("error during compression: {}", err)
> -                    }),
> -                    Level::Default,
> -                ))
> +                    }))
> +                    .zlib(true)
> +                    .build(),
> +                )
>              })
>          }
>          None => resp,
> @@ -711,7 +713,7 @@ async fn simple_static_file_download(
>  
>      let mut response = match compression {
>          Some(CompressionMethod::Deflate) => {
> -            let mut enc = DeflateEncoder::with_quality(data, Level::Default);
> +            let mut enc = DeflateEncoder::builder(data).zlib(true).build();
>              enc.compress_vec(&mut file, CHUNK_SIZE_LIMIT as usize)
>                  .await?;
>              let mut response = Response::new(enc.into_inner().into());
> @@ -752,10 +754,11 @@ async fn chunked_static_file_download(
>                  header::CONTENT_ENCODING,
>                  CompressionMethod::Deflate.content_encoding(),
>              );
> -            Body::wrap_stream(DeflateEncoder::with_quality(
> -                AsyncReaderStream::new(file),
> -                Level::Default,
> -            ))
> +            Body::wrap_stream(
> +                DeflateEncoder::builder(AsyncReaderStream::new(file))
> +                    .zlib(true)
> +                    .build(),
> +            )
>          }
>          None => Body::wrap_stream(AsyncReaderStream::new(file)),
>      };



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel