[pve-devel] [PATCH 2/2] rest : handle application/x-spice-configuration response format
Alexandre Derumier
aderumier at odiso.com
Fri Jun 21 10:33:21 CEST 2013
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/HTTPServer.pm | 2 +-
PVE/REST.pm | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/PVE/HTTPServer.pm b/PVE/HTTPServer.pm
index 0ba99f7..3ed5ae2 100755
--- a/PVE/HTTPServer.pm
+++ b/PVE/HTTPServer.pm
@@ -46,7 +46,7 @@ my $baseuri = "/api2";
sub split_abs_uri {
my ($abs_uri) = @_;
- my ($format, $rel_uri) = $abs_uri =~ m/^\Q$baseuri\E\/+(html|text|json|extjs|png|htmljs)(\/.*)?$/;
+ my ($format, $rel_uri) = $abs_uri =~ m/^\Q$baseuri\E\/+(html|text|json|extjs|png|htmljs|spiceconfig)(\/.*)?$/;
$rel_uri = '/' if !$rel_uri;
return wantarray ? ($rel_uri, $format) : $rel_uri;
diff --git a/PVE/REST.pm b/PVE/REST.pm
index d59f88d..9dafaf5 100644
--- a/PVE/REST.pm
+++ b/PVE/REST.pm
@@ -111,6 +111,17 @@ sub format_response_data {
# we use this for extjs file upload forms
$ct = 'text/html;charset=UTF-8';
$raw = encode_entities(to_json($data, {allow_nonref => 1}));
+ } elsif ($format eq 'spiceconfig') {
+ $ct = 'application/x-spice-configuration;charset=UTF-8';
+ if ($data && ref($data) && ref($data->{data})) {
+ $raw = "[virt-viewer]\n";
+ $raw .= "title=$data->{data}->{title}\n" if $data->{data}->{title};
+ $raw .= "type=$data->{data}->{type}\n" if $data->{data}->{type};
+ $raw .= "host=$data->{data}->{host}\n" if $data->{data}->{host};
+ $raw .= "port=$data->{data}->{port}\n" if $data->{data}->{port};
+ $raw .= "password=$data->{data}->{password}\n" if $data->{data}->{password};
+ $raw .= "proxy=$data->{data}->{proxy}\n" if $data->{data}->{proxy};
+ }
} else {
$ct = 'text/plain;charset=UTF-8';
$raw = to_json($data, {utf8 => 1, allow_nonref => 1, pretty => 1});
--
1.7.10.4
More information about the pve-devel
mailing list