Async-Microservice
view release on metacpan or search on metacpan
lib/Async/MicroserviceReq.pm view on Meta::CPAN
sub text_plain {
my ( $self, @text ) = @_;
return $self->respond( 200, [], join( "\n", ( @text, q{} ) ) );
}
sub _should_wrap_payload_as_json {
my ( $self, $headers_as_hash, $payload ) = @_;
return ( $self->want_json
&& !ref($payload)
&& !$headers_as_hash->{'content-type'} ) ? 1 : 0;
}
sub _wrap_payload {
my ( $self, $state ) = @_;
return $state->{payload}
unless $self->_should_wrap_payload_as_json( $state->{headers_as_hash},
$state->{payload} );
if ( $state->{status} < 400 ) {
lib/Async/MicroserviceReq.pm view on Meta::CPAN
return $state;
}
sub _emit_response {
my ( $self, $state ) = @_;
push(
@{ $state->{headers} },
( 'Content-Type' => ( $state->{content_type} || 'text/plain' ) )
) unless ( $state->{headers_as_hash}->{'content-type'} );
return $self->plack_respond->(
[ $state->{status},
[ @no_cache_headers, @{ $state->{headers} } ],
[ $state->{payload} ]
]
);
}
sub respond {
( run in 2.394 seconds using v1.01-cache-2.11-cpan-524268b4103 )