[pmg-devel] [PATCH pmg-api v2 01/10] HTTPServer: extend download functionality
Dominik Csapak
d.csapak at proxmox.com
Mon Sep 30 14:55:25 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)
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"
+ }
+
} else {
$resp->{data} = $result;
}
--
2.20.1
More information about the pmg-devel
mailing list