[pmg-devel] [PATCH pmg-api v2 01/10] HTTPServer: extend download functionality

Stoiko Ivanov s.ivanov at proxmox.com
Thu Oct 3 17:38:08 CEST 2019


On Mon, 30 Sep 2019 14:55:25 +0200
Dominik Csapak <d.csapak at proxmox.com> wrote:

> allow object as return value for 'download' api calls
> this way, we can give additional information for download apis
> (like the content-type)
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> changes from v1:
> * simply assign the result into 'download' property instead of copying
>   some properties -> more robust and future proof
>  src/PMG/HTTPServer.pm | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/src/PMG/HTTPServer.pm b/src/PMG/HTTPServer.pm
> index 6997dd5..cedebcb 100755
> --- a/src/PMG/HTTPServer.pm
> +++ b/src/PMG/HTTPServer.pm
> @@ -162,9 +162,13 @@ sub rest_handler {
>  	};
>  
>  	if ($info->{download}) {
> -	    die "download methods should have return type 'string' - internal error"
> -		if ($info->{returns}->{type} ne 'string');
> -	    $resp->{download} = $result;
> +	    my $type =  $info->{returns}->{type};
> +	    if ($type eq 'string' || $type eq 'object') {
> +		$resp->{download} = $result;
> +	    } else {
> +		die "download methods should have return type 'string' or 'object' - internal error"
nit: s/return/returned/
> +	    }
> +
>  	} else {
>  	    $resp->{data} = $result;
>  	}




More information about the pmg-devel mailing list