| 1 | package Search::Elasticsearch::Cxn::HTTPTiny; | ||||||||||||||||||||||||||||
| 2 | 29 | $Search::Elasticsearch::Cxn::HTTPTiny::VERSION = '6.80'; | |||||||||||||||||||||||||||
| 3 | 29 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 29 | with 'Search::Elasticsearch::Role::Cxn', 'Search::Elasticsearch::Role::Is_Sync'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 29 | ▶ | use HTTP::Tiny 0.043 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 29 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 29 | my $Cxn_Error = qr/ Connection.(?:timed.out|re(?:set|fused)) | |||||||||||||||||||||||||||
| 10 | | connect:.timeout | ||||||||||||||||||||||||||||
| 11 | | Host.is.down | ||||||||||||||||||||||||||||
| 12 | | No.route.to.host | ||||||||||||||||||||||||||||
| 13 | | temporarily.unavailable | ||||||||||||||||||||||||||||
| 14 | /x; | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | #=================================== | ||||||||||||||||||||||||||||
| 17 | sub perform_request { | ||||||||||||||||||||||||||||
| 18 | #=================================== | ||||||||||||||||||||||||||||
| 19 | my ( $self, $params ) = @_; | ||||||||||||||||||||||||||||
| 20 | my $uri = $self->build_uri($params); | ||||||||||||||||||||||||||||
| 21 | my $method = $params->{method}; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | my %args; | ||||||||||||||||||||||||||||
| 24 | if ( defined $params->{data} ) { | ||||||||||||||||||||||||||||
| 25 | $args{content} = $params->{data}; | ||||||||||||||||||||||||||||
| 26 | $args{headers}{'Content-Type'} = $params->{mime_type}; | ||||||||||||||||||||||||||||
| 27 | $args{headers}{'Content-Encoding'} = $params->{encoding} | ||||||||||||||||||||||||||||
| 28 | if $params->{encoding}; | ||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | my $handle = $self->handle; | ||||||||||||||||||||||||||||
| 32 | $handle->timeout( $params->{timeout} || $self->request_timeout ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | my $response = $handle->request( $method, "$uri", \%args ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | return $self->process_response( | ||||||||||||||||||||||||||||
| 37 | $params, # request | ||||||||||||||||||||||||||||
| 38 | $response->{status}, # code | ||||||||||||||||||||||||||||
| 39 | $response->{reason}, # msg | ||||||||||||||||||||||||||||
| 40 | $response->{content}, # body | ||||||||||||||||||||||||||||
| 41 | $response->{headers} # headers | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #=================================== | ||||||||||||||||||||||||||||
| 46 | sub error_from_text { | ||||||||||||||||||||||||||||
| 47 | #=================================== | ||||||||||||||||||||||||||||
| 48 | 1 | ▶ | local $_ = $_[2]; | ||||||||||||||||||||||||||
|
Subroutine
error_from_text: called CC=5 SCAR=26.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | return | ||||||||||||||||||||||||||||
| 50 | 1 | ▶ | /[Tt]imed out/ ? 'Timeout' | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 51 | : /Unexpected end of stream/ ? 'ContentLength' | ||||||||||||||||||||||||||||
| 52 | : /SSL connection failed/ ? 'SSL' | ||||||||||||||||||||||||||||
| 53 | : /$Cxn_Error/ ? 'Cxn' | ||||||||||||||||||||||||||||
| 54 | : 'Request'; | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | #=================================== | ||||||||||||||||||||||||||||
| 58 | sub _build_handle { | ||||||||||||||||||||||||||||
| 59 | #=================================== | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_handle: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 61 | 0 | my %args = ( default_headers => $self->default_headers ); | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( $self->is_https && $self->has_ssl_options ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->is_https and $self->has_ssl_options
MC/DC0%0/2
$self->is_https and $self->has_ssl_options
$self->is_https
$self->has_ssl_options
Truth table0%0/3
A and B
A= $self->is_httpsB= $self->has_ssl_options
| |||||||||||||||||||||||||||||
| 63 | 0 | $args{SSL_options} = $self->ssl_options; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( $args{SSL_options}{SSL_verify_mode} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | $args{verify_ssl} = 1; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | return HTTP::Tiny->new( %args, %{ $self->handle_args } ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 29 | 1; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # ABSTRACT: A Cxn implementation which uses HTTP::Tiny | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||