From 127dbe7c7dced8bb3ac7f9af3216b20db67633d1 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 24 Nov 2021 15:47:47 +0100 Subject: [PATCH] download-stream: allow the api call to set the content-encoding this is useful if we want to pipe the output of a program e.g. through gzip Signed-off-by: Dominik Csapak Signed-off-by: Thomas Lamprecht --- src/PVE/APIServer/AnyEvent.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm index c159b8d..31556ce 100644 --- a/src/PVE/APIServer/AnyEvent.pm +++ b/src/PVE/APIServer/AnyEvent.pm @@ -413,6 +413,7 @@ sub send_file_start { if (ref($download) eq 'HASH') { $mime = $download->{'content-type'}; + my $encoding = $download->{'content-encoding'}; if ($download->{path} && $download->{stream} && $reqstate->{request}->header('PVEDisableProxy')) @@ -424,6 +425,7 @@ sub send_file_start { pvestreamfile => $download->{path}, Content_Type => $mime, ); + $header->header('Content-Encoding' => $encoding) if defined($encoding); # we need some data so Content-Length gets set correctly and # the proxy doesn't wait for more data - place a canary my $resp = HTTP::Response->new(200, "OK", $header, "error canary"); @@ -441,6 +443,7 @@ sub send_file_start { if ($download->{stream}) { my $header = HTTP::Headers->new(Content_Type => $mime); + $header->header('Content-Encoding' => $encoding) if defined($encoding); my $resp = HTTP::Response->new(200, "OK", $header); $self->response($reqstate, $resp, undef, 1, 0, $fh); return; -- 2.39.2