File Coverage

blib/lib/OpenSearch/Client/Cxn/HTTPTiny.pm
Criterion Covered Total %
statement 11 17 64.7
branch 1 12 8.3
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 16 35 45.7


line stmt bran cond sub pod time code
1             # OpenSearch::Client is an unofficial client for OpenSearch.
2             # It is derived from Search::Elasticsearch version 7.714
3             # License details from the original work are contained in the
4             # NOTICE file distributed with this work.
5             #
6             #-----------------------------------------------------------------------
7             # OpenSearch::Client
8             #-----------------------------------------------------------------------
9             # Copyright 2026 Mark Dootson
10             #
11             # Licensed under the Apache License, Version 2.0 (the "License");
12             # you may not use this file except in compliance with the License.
13             # You may obtain a copy of the License at
14             #
15             # http://www.apache.org/licenses/LICENSE-2.0
16             #
17             # Unless required by applicable law or agreed to in writing, software
18             # distributed under the License is distributed on an "AS IS" BASIS,
19             # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20             # See the License for the specific language governing permissions and
21             # limitations under the License.
22              
23             package OpenSearch::Client::Cxn::HTTPTiny;
24             $OpenSearch::Client::Cxn::HTTPTiny::VERSION = '3.007002';
25 29     29   13503 use Moo;
  29         53  
  29         161  
26             with 'OpenSearch::Client::Role::Cxn', 'OpenSearch::Client::Role::Is_Sync';
27              
28 29     29   26041 use HTTP::Tiny 0.089 ();
  29         1182293  
  29         1136  
29 29     29   199 use namespace::clean;
  29         44  
  29         276  
30              
31             my $Cxn_Error = qr/ Connection.(?:timed.out|re(?:set|fused))
32             | connect:.timeout
33             | Host.is.down
34             | No.route.to.host
35             | temporarily.unavailable
36             /x;
37              
38             #===================================
39             sub perform_request {
40             #===================================
41             my ( $self, $params ) = @_;
42             my $uri = $self->build_uri($params);
43             my $method = $params->{method};
44              
45             my %args;
46             if ( defined $params->{data} ) {
47             $args{content} = $params->{data};
48             $args{headers}{'Content-Type'} = $params->{mime_type};
49             $args{headers}{'Content-Encoding'} = $params->{encoding}
50             if $params->{encoding};
51             }
52              
53             my $handle = $self->handle;
54             $handle->timeout( $params->{timeout} || $self->request_timeout );
55              
56             my $response = $handle->request( $method, "$uri", \%args );
57              
58             return $self->process_response(
59             $params, # request
60             $response->{status}, # code
61             $response->{reason}, # msg
62             $response->{content}, # body
63             $response->{headers} # headers
64             );
65             }
66              
67             #===================================
68             sub error_from_text {
69             #===================================
70 1     1 0 3 local $_ = $_[2];
71             return
72 1 0       8 /[Tt]imed out/ ? 'Timeout'
    0          
    0          
    50          
73             : /Unexpected end of stream/ ? 'ContentLength'
74             : /SSL connection failed/ ? 'SSL'
75             : /$Cxn_Error/ ? 'Cxn'
76             : 'Request';
77             }
78              
79             #===================================
80             sub _build_handle {
81             #===================================
82 0     0     my $self = shift;
83 0           my %args = ( default_headers => $self->default_headers );
84            
85 0 0         if ( $self->is_https ) {
86             $args{SSL_options}
87 0 0         = $self->has_ssl_options
88             ? $self->ssl_options
89             : { SSL_verify_mode => 0x01 };
90             }
91            
92 0           return HTTP::Tiny->new( %args, %{ $self->handle_args } );
  0            
93             }
94              
95             1;
96              
97             __END__