public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH http-server 02/09] proxy: strip chunked framing headers from decoded responses
Date: Mon, 30 Nov 2026 01:58:06 +0100	[thread overview]
Message-ID: <20261130010113.2166775-3-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261130010113.2166775-1-t.lamprecht@proxmox.com>

AnyEvent::HTTP decodes chunked upstream responses but leaves the
Transfer-Encoding and Trailer headers intact. Forwarding them alongside
the Content-Length of the decoded body causes clients to misparse the
body as chunked. In addition, response() checked Perl truthiness on
$content rather than definedness and length, so a decoded empty body
("") omitted Content-Length on keep-alive 200 OK responses and a "0"
body was dropped altogether.

Strip Transfer-Encoding and Trailer before forwarding, and frame
non-stream responses whenever the status permits a body and $content
is defined (keeping 1xx, 204, 304, and streamed responses without
Content-Length or body). This is needed once API2 endpoints stream
chunked HTTP/1.1 responses (for example from pvedaemon through
pveproxy). The proxy still buffers the full response rather than
forwarding it incrementally.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 src/PVE/APIServer/AnyEvent.pm | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
index 7bbd586..36ad253 100644
--- a/src/PVE/APIServer/AnyEvent.pm
+++ b/src/PVE/APIServer/AnyEvent.pm
@@ -406,7 +406,8 @@ sub response {
         $content = '';
     }
 
-    if ($code =~ /^(1\d\d|[23]04)$/) {
+    my $no_body = $code =~ /^(1[0-9][0-9]|[23]04)$/;
+    if ($no_body) {
         # make sure informational, no content and not modified response send no content
         $content = "";
     }
@@ -432,7 +433,7 @@ sub response {
     $resp->header('Server' => "pve-api-daemon/3.0");
 
     my $content_length;
-    if ($content && !$stream_fh) {
+    if (!$stream_fh && !$no_body && defined($content)) {
 
         $content_length = length($content);
 
@@ -467,7 +468,7 @@ sub response {
     #print "SEND(without content) $res\n" if $self->{debug};
 
     $res .= "\015\012";
-    $res .= $content if $content && !$stream_fh;
+    $res .= $content if !$stream_fh && !$no_body && defined($content) && length($content);
 
     $self->log_request($reqstate, $reqstate->{request});
 
@@ -957,6 +958,9 @@ sub proxy_request {
                     my $stream = delete $hdr->{pvestreamfile};
                     delete $hdr->{URL};
                     delete $hdr->{HTTPVersion};
+                    # AnyEvent::HTTP already decoded a chunked body but keeps the framing headers.
+                    delete $hdr->{'transfer-encoding'};
+                    delete $hdr->{trailer};
                     my $header = HTTP::Headers->new(%$hdr);
                     if (my $location = $header->header('Location')) {
                         $location =~ s|^http://localhost:85||;
-- 
2.47.3





  parent reply	other threads:[~2026-11-30  1:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  0:58 [PATCH http-server,apiclient,manager 00/09] async and streaming pull metric export Thomas Lamprecht
2026-11-30  0:58 ` [PATCH http-server 01/09] response: support deferred async API2 responses Thomas Lamprecht
2026-11-30  0:58 ` Thomas Lamprecht [this message]
2026-11-30  0:58 ` [PATCH http-server 03/09] response: support incremental streaming " Thomas Lamprecht
2026-11-30  0:58 ` [PATCH apiclient 04/09] add non-blocking AnyEvent API client Thomas Lamprecht
2026-11-30  0:58 ` [PATCH apiclient 05/09] add bounded AnyEvent request pool with backpressure and timeout Thomas Lamprecht
2026-11-30  0:58 ` [PATCH manager 06/09] api: metrics export: fetch remote nodes asynchronously Thomas Lamprecht
2026-11-30  0:58 ` [PATCH manager 07/09] api: metrics export: stream sorted metrics via incremental k-way merge Thomas Lamprecht
2026-11-30  0:58 ` [PATCH manager 08/09] api: metrics export: add unsorted pass-through streaming option Thomas Lamprecht
2026-11-30  0:58 ` [PATCH manager 09/09] test: add pull metric export test suite Thomas Lamprecht
2026-12-01 10:13 ` [PATCH http-server,apiclient,manager 00/09] async and streaming pull metric export Jonas Theisen
2026-12-01 10:22 ` superseded: " 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=20261130010113.2166775-3-t.lamprecht@proxmox.com \
    --to=t.lamprecht@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 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