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

Dominik Csapak d.csapak at proxmox.com
Thu Sep 26 12:28:05 CEST 2019


allow object as return value for 'download' api calls
this way, we can give additional information for download apis
(like the content-type and if it should be deleted after)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PMG/HTTPServer.pm | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/PMG/HTTPServer.pm b/src/PMG/HTTPServer.pm
index 6997dd5..10ef67d 100755
--- a/src/PMG/HTTPServer.pm
+++ b/src/PMG/HTTPServer.pm
@@ -162,9 +162,16 @@ 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;
+	    if ($info->{returns}->{type} eq 'object') {
+		$resp->{download} = $result->{path};
+		$resp->{'content-type'} = $result->{'content-type'};
+		$resp->{delete} = $result->{delete};
+	    } elsif ($info->{returns}->{type} eq 'string') {
+		$resp->{download} = $result;
+	    } else {
+		die "download methods should have return type 'string' or 'object' - internal error"
+	    }
+
 	} else {
 	    $resp->{data} = $result;
 	}
-- 
2.20.1




More information about the pmg-devel mailing list