[pve-devel] [PATCH manager] pvesh: decode streamed responses
Christoph Heiss
c.heiss at proxmox.com
Wed Jun 7 14:04:52 CEST 2023
On Wed, Jun 07, 2023 at 08:54:44AM +0200, Wolfgang Bumiller wrote:
> looks mostly fine, I'd like some minor changes:
Thanks for the review!
>
> On Thu, Mar 30, 2023 at 11:25:20AM +0200, Christoph Heiss wrote:
> > [..]
> >
> > +my $handle_streamed_response = sub {
> > + my ($download) = @_;
> > + my ($fh, $path, $encoding, $type) =
> > + $download->@{'fh', 'path', 'content-encoding', 'content-type'};
> > +
> > + die "{download} returned but neither fh nor path given\n"
> > + if !defined($fh) and !defined($path);
>
> ^ style nit: use && here please
Ack.
>
> > +
> > + if (defined($path)) {
> > + open($fh, '<', $path)
> > + or die "open stream path '$path' for reading failed: $!\n";
> > + }
> > +
> > + local $/;
> > + my $data = <$fh>;
> > +
> > + if (defined($encoding)) {
> > + die "unknown 'content-encoding' $encoding\n" if $encoding ne 'gzip';
> > + my $out;
> > + gunzip(\$data => \$out);
> > + $data = $out;
> > + }
> > +
> > + if (defined($type) && not $type =~ qw!^text/plain!) {
>
> style: `$type !~ …` instead of 'not $type =~ …'
Did not know !~ existed as operator as well :^)
>
> > + die "unknown 'content-type' $type\n" if not $type =~ qw!^application/json!;
>
> Would be nice to move the $type check above the part doing the gunzip()
> to avoid unnecessary work.
I'll restructure that, thanks.
>
> > [..]
More information about the pve-devel
mailing list