Prettify json on manager conf export (#2292)

This commit is contained in:
Maxime Besson 2020-08-25 16:09:06 +02:00
parent bcb6c428f1
commit d5b47115ee
2 changed files with 19 additions and 3 deletions

View File

@ -769,8 +769,8 @@ sub metadata {
return $self->sendJSONresponse(
$req,
$self->currentConf,
forceJSON => 1,
headers => [
pretty => 1,
headers => [
'Content-Disposition' => "Attachment; filename=lmConf-$c.json"
],
);

View File

@ -125,7 +125,23 @@ sub sendJSONresponse {
$args{headers} ||= [ $req->spliceHdrs ];
my $type = 'application/json; charset=utf-8';
if ( ref $j ) {
eval { $j = $_json->encode($j); };
eval {
if ( $args{pretty} ) {
# This avoids changing the settings of the $_json reference
$j = to_json(
$j,
{
allow_nonref => 1,
pretty => 1,
canonical => 1
}
);
}
else {
$j = $_json->encode($j);
}
};
return $self->sendError( $req, $@ ) if ($@);
}
return [ $args{code}, [ 'Content-Type' => $type, @{ $args{headers} } ],