my $class = ref($this) || $this;
my $self = $class->SUPER::new(%args);
-
+
$self->{rpcenv} = PMG::RESTEnvironment->init(
$self->{trusted_env} ? 'priv' : 'pub', atfork => sub { $self->atfork_handler() });
}
sub rest_handler {
- my ($self, $clientip, $method, $rel_uri, $auth, $params) = @_;
+ my ($self, $clientip, $method, $rel_uri, $auth, $params, $format) = @_;
my $rpcenv = $self->{rpcenv};
+ $rpcenv->set_format($format);
my $resp = {
status => HTTP_NOT_IMPLEMENTED,
}
}
+
+ my $result = $handler->handle($info, $uri_param);
+
$resp = {
- data => $handler->handle($info, $uri_param),
info => $info, # useful to format output
status => HTTP_OK,
};
+ if ($info->{download}) {
+ die "download methods should have return type 'string' - internal error"
+ if ($info->{returns}->{type} ne 'string');
+ $resp->{download} = $result;
+ } else {
+ $resp->{data} = $result;
+ }
+
if (my $count = $rpcenv->get_result_attrib('total')) {
$resp->{total} = $count;
}
$rpcenv->set_user(undef); # clear after request
$rpcenv->set_role(undef); # clear after request
+ $rpcenv->set_format(undef); # clear after request
if ($err) {
$resp = { info => $info };