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