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

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Oct 3 17:46:51 CEST 2019


On 10/3/19 5:38 PM, Stoiko Ivanov wrote:
> 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/

or maybe
"download info return type needs to be 'string' or 'object' - internal error"

or maybe a bit more understandable:
"API calls which trigger downloads can only have 'string' or 'object' as return type"



More information about the pmg-devel mailing list