App-ElasticSearch-Utilities
view release on metacpan or search on metacpan
lib/App/ElasticSearch/Utilities/Connection.pm view on Meta::CPAN
$ua->add_handler( response_done => sub {
my ($response,$lwp_ua,$headers) = @_;
debug( {color=>'magenta'}, "respone_done handler, got:");
debug_var($response);
my $ctype = $response->content_type() || 'invalid';
# JSON Transform
if( $ctype =~ m{^application/json\b} ) {
debug({color=>'yellow',indent=>1},"JSON Decoding Response Content");
eval {
my $decoded = decode_json( $response->content );
$response->content($decoded);
};
}
elsif ( $response->is_success && $ctype =~ m{^text/plain} ) {
# Plain text transform for the _cat API
debug({color=>'yellow',indent=>1},"Plain Text Transform Response Content");
my $decoded = [
grep { defined && length && !/^\s+$/ }
split /\r?\n/, $response->content
];
debug_var($decoded);
$response->content($decoded);
}
if( my $content = $response->content ) {
debug({color=>'yellow'}, "After translation:");
if( is_ref($content) ) {
debug_var( $content );
}
else{
debug( $content );
}
}
( run in 0.551 second using v1.01-cache-2.11-cpan-26ccb49234f )