public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox] rest-server: Encode with zlib headers
Date: Tue, 16 Jul 2024 11:22:47 +0200	[thread overview]
Message-ID: <20240716092247.212133-1-m.sandoval@proxmox.com> (raw)

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.

 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)),
     };
-- 
2.39.2



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


             reply	other threads:[~2024-07-16  9:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16  9:22 Maximiliano Sandoval [this message]
2024-07-17 15:49 ` Max Carrara
2024-07-18 16:08   ` Thomas Lamprecht
2024-07-22  5:56     ` Max Carrara
2024-07-22  6:20       ` Thomas Lamprecht
2024-07-25  7:35         ` Maximiliano Sandoval
2024-07-22  6:12 ` [pbs-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240716092247.212133-1-m.sandoval@proxmox.com \
    --to=m.sandoval@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal