1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
# Licensed to Elasticsearch B.V under one or more agreements.
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information
package Search::Elasticsearch::Role::Transport;
$Search::Elasticsearch::Role::Transport::VERSION = '8.12';
use Moo::Role;
requires qw(perform_request);
use Try::Tiny;
use Search::Elasticsearch::Util qw(parse_params is_compat);
use namespace::clean;
has 'serializer' => ( is => 'ro', required => 1 );
has 'logger' => ( is => 'ro', required => 1 );
has 'send_get_body_as' => ( is => 'ro', default => 'GET' );
has 'cxn_pool' => ( is => 'ro', required => 1 );
#===================================
sub BUILD {
#===================================
my $self = shift;
my $pool = $self->cxn_pool;
is_compat( 'cxn_pool', $self, $pool );
is_compat( 'cxn', $self, $pool->cxn_factory->cxn_class );
return $self;
}
#===================================
sub tidy_request {
#===================================
my ( $self, $params ) = parse_params(@_);
$params->{method} ||= 'GET';
$params->{path} ||= '/';
$params->{qs} ||= {};
$params->{ignore} ||= [];
my $body = $params->{body};
return $params unless defined $body;
$params->{serialize} ||= 'std';
$params->{data}
= $params->{serialize} eq 'std'
? $self->serializer->encode($body)
: $self->serializer->encode_bulk($body);
if ( $params->{method} eq 'GET' ) {
my $send_as = $self->send_get_body_as;
if ( $send_as eq 'POST' ) {
$params->{method} = 'POST';
}
elsif ( $send_as eq 'source' ) {
$params->{qs}{source} = delete $params->{data};
delete $params->{body};
}
}
$params->{mime_type} ||= $self->serializer->mime_type;
return $params;
}
1;
#ABSTRACT: Transport role providing interface between the client class and the Elasticsearch cluster
__END__
=pod
=encoding UTF-8
=head1 NAME
Search::Elasticsearch::Role::Transport - Transport role providing interface between the client class and the Elasticsearch cluster
=head1 VERSION
version 8.12
=head1 AUTHOR
Enrico Zimuel <enrico.zimuel@elastic.co>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2024 by Elasticsearch BV.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
=cut
|