Commit 09128602 authored by Alexandre Derumier's avatar Alexandre Derumier Committed by Dietmar Maurer

rest : handle application/x-spice-configuration response format

Signed-off-by: 's avatarAlexandre Derumier <aderumier@odiso.com>
parent 3d1ccfa6
...@@ -46,7 +46,7 @@ my $baseuri = "/api2"; ...@@ -46,7 +46,7 @@ my $baseuri = "/api2";
sub split_abs_uri { sub split_abs_uri {
my ($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; $rel_uri = '/' if !$rel_uri;
return wantarray ? ($rel_uri, $format) : $rel_uri; return wantarray ? ($rel_uri, $format) : $rel_uri;
......
...@@ -111,6 +111,17 @@ sub format_response_data { ...@@ -111,6 +111,17 @@ sub format_response_data {
# we use this for extjs file upload forms # we use this for extjs file upload forms
$ct = 'text/html;charset=UTF-8'; $ct = 'text/html;charset=UTF-8';
$raw = encode_entities(to_json($data, {allow_nonref => 1})); $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 { } else {
$ct = 'text/plain;charset=UTF-8'; $ct = 'text/plain;charset=UTF-8';
$raw = to_json($data, {utf8 => 1, allow_nonref => 1, pretty => 1}); $raw = to_json($data, {utf8 => 1, allow_nonref => 1, pretty => 1});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment