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