all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Maximiliano Sandoval <m.sandoval@proxmox.com>
Subject: Re: [pve-devel] [PATCH http-server] http: support Content-Encoding=deflate
Date: Tue, 16 Apr 2024 13:49:36 +0200	[thread overview]
Message-ID: <0186d4d1-f8eb-4302-a71e-4456235492a7@proxmox.com> (raw)
In-Reply-To: <20240416114404.76400-1-m.sandoval@proxmox.com>

Am 16/04/2024 um 13:44 schrieb Maximiliano Sandoval:
> Add support for compressing the body of responses with
> `Content-Encoding=deflate` as per [RFC9110]. Note that in this context
> `deflate` is actually a "zlib" data format as defined in [RFC1950].
> 
> [RFC9110] https://www.rfc-editor.org/rfc/rfc9110#name-deflate-coding
> [RFC1950] https://www.rfc-editor.org/rfc/rfc1950
> 
> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> ---
>  src/PVE/APIServer/AnyEvent.pm | 23 +++++++++++++++++------
>  1 file changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
> index b60b825..a43d6bb 100644
> --- a/src/PVE/APIServer/AnyEvent.pm
> +++ b/src/PVE/APIServer/AnyEvent.pm
> @@ -123,6 +123,7 @@ sub cleanup_reqstate {
>      delete $reqstate->{request};
>      delete $reqstate->{proto};
>      delete $reqstate->{accept_gzip};
> +    delete $reqstate->{accept_deflate};
>      delete $reqstate->{starttime};
>  
>      if ($reqstate->{tmpfilename}) {
> @@ -288,7 +289,7 @@ sub response {
>      $reqstate->{hdl}->timeout($self->{timeout});
>  
>      $nocomp = 1 if !$self->{compression};
> -    $nocomp = 1 if !$reqstate->{accept_gzip};
> +    $nocomp = 1 if !$reqstate->{accept_gzip} && !$reqstate->{accept_deflate};
>  
>      my $code = $resp->code;
>      my $msg = $resp->message || HTTP::Status::status_message($code);
> @@ -333,11 +334,17 @@ sub response {
>  	$content_length = length($content);
>  
>  	if (!$nocomp && ($content_length > 1024)) {
> -	    my $comp = Compress::Zlib::memGzip($content);
> -	    $resp->header('Content-Encoding', 'gzip');
> -	    $content = $comp;
> -	    $content_length = length($content);
> +	    if ($reqstate->{accept_gzip}) {
> +		my $comp = Compress::Zlib::memGzip($content);
> +		$resp->header('Content-Encoding', 'gzip');
> +		$content = $comp;
> +	    } elsif ($reqstate->{accept_deflate}) {
> +		my $comp = Compress::Zlib::compress($content);
> +		$resp->header('Content-Encoding', 'deflate');
> +		$content = $comp;
> +	    }
>  	}
> +	$content_length = length($content);
>  	$resp->header("Content-Length" => $content_length);
>  	$reqstate->{log}->{content_length} = $content_length;
>  
> @@ -735,7 +742,10 @@ sub proxy_request {
>  	    if $auth->{api_token};
>  	$headers->{'CSRFPreventionToken'} = $auth->{token}
>  	    if $auth->{token};
> -	$headers->{'Accept-Encoding'} = 'gzip' if ($reqstate->{accept_gzip} && $self->{compression});
> +	if ($self->{compression}) {
> +	    $headers->{'Accept-Encoding'} = 'deflate' if $reqstate->{accept_deflate};
> +	    $headers->{'Accept-Encoding'} = 'gzip' if $reqstate->{accept_gzip};

it might warrant a comment (and a hint in the commit message) that gzip is
favored, otherwise it might seem like a bug that if both, accept_deflate and
accept_gzip are set, only the gzip one is set (even though passing a list
would be supported), or was this overlooked?




      reply	other threads:[~2024-04-16 11:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-16 11:44 Maximiliano Sandoval
2024-04-16 11:49 ` Thomas Lamprecht [this message]

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=0186d4d1-f8eb-4302-a71e-4456235492a7@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=m.sandoval@proxmox.com \
    --cc=pve-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal