* [pve-devel] [PATCH http-server 1/2] allow 'download' to be passed from API handler
@ 2021-04-01 15:30 Stefan Reiter
2021-04-01 15:30 ` [pve-devel] [PATCH common 2/2] JSONSchema: don't cycle-check 'download' responses Stefan Reiter
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Reiter @ 2021-04-01 15:30 UTC (permalink / raw)
To: pve-devel
PVE::HTTPServer in pve-manager wraps the API return value in a 'data'
element, look for a 'download' element there too to allow an API call to
instruct the HTTP server to return a file via path or filehandle.
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
This will be needed for the single file restore API.
PVE/APIServer/AnyEvent.pm | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/PVE/APIServer/AnyEvent.pm b/PVE/APIServer/AnyEvent.pm
index 8a1af54..60a2a1c 100644
--- a/PVE/APIServer/AnyEvent.pm
+++ b/PVE/APIServer/AnyEvent.pm
@@ -812,7 +812,10 @@ sub handle_api2_request {
$delay = 0 if $delay < 0;
}
- if (defined(my $download = $res->{download})) {
+ my $download = $res->{download};
+ $download //= $res->{data}->{download}
+ if defined($res->{data}) && ref($res->{data}) eq 'HASH';
+ if (defined($download)) {
send_file_start($self, $reqstate, $download);
return;
}
--
2.20.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pve-devel] [PATCH common 2/2] JSONSchema: don't cycle-check 'download' responses
2021-04-01 15:30 [pve-devel] [PATCH http-server 1/2] allow 'download' to be passed from API handler Stefan Reiter
@ 2021-04-01 15:30 ` Stefan Reiter
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Reiter @ 2021-04-01 15:30 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
Note that this happens before the result is put in '->{data}' so that part of
the previous patch is not necessary here.
src/PVE/JSONSchema.pm | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index 4864549..c29c777 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -1178,7 +1178,10 @@ sub validate {
# we can disable that in the final release
# todo: is there a better/faster way to detect cycles?
my $cycles = 0;
- find_cycle($instance, sub { $cycles = 1 });
+ # 'download' responses can contain a filehandle, don't cycle-check that as
+ # it produces a warning
+ my $is_download = ref($instance) eq 'HASH' && exists($instance->{download});
+ find_cycle($instance, sub { $cycles = 1 }) if !$is_download;
if ($cycles) {
add_error($errors, undef, "data structure contains recursive cycles");
} elsif ($schema) {
--
2.20.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-04-01 15:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 15:30 [pve-devel] [PATCH http-server 1/2] allow 'download' to be passed from API handler Stefan Reiter
2021-04-01 15:30 ` [pve-devel] [PATCH common 2/2] JSONSchema: don't cycle-check 'download' responses Stefan Reiter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox