Prettify json on manager conf export (#2292)

Moo
Maxime Besson 5 years ago
parent bcb6c428f1
commit d5b47115ee
  1. 4
      lemonldap-ng-common/lib/Lemonldap/NG/Common/Conf/RESTServer.pm
  2. 18
      lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI.pm

@ -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"
],
);

@ -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} } ],

Loading…
Cancel
Save