line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Elasticsearch::Cxn::HTTPTiny; |
2
|
|
|
|
|
|
|
$Elasticsearch::Cxn::HTTPTiny::VERSION = '1.05'; |
3
|
16
|
|
|
16
|
|
12230
|
use Moo; |
|
16
|
|
|
|
|
686
|
|
|
16
|
|
|
|
|
117
|
|
4
|
|
|
|
|
|
|
with 'Elasticsearch::Role::Cxn::HTTP', |
5
|
|
|
|
|
|
|
'Elasticsearch::Role::Cxn', |
6
|
|
|
|
|
|
|
'Elasticsearch::Role::Is_Sync'; |
7
|
|
|
|
|
|
|
|
8
|
16
|
|
|
16
|
|
25016
|
use HTTP::Tiny 0.043 (); |
|
16
|
|
|
|
|
1163643
|
|
|
16
|
|
|
|
|
1010
|
|
9
|
16
|
|
|
16
|
|
214
|
use namespace::clean; |
|
16
|
|
|
|
|
36
|
|
|
16
|
|
|
|
|
326
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $Cxn_Error = qr/ Connection.(?:timed.out|re(?:set|fused)) |
12
|
|
|
|
|
|
|
| connect:.timeout |
13
|
|
|
|
|
|
|
| Host.is.down |
14
|
|
|
|
|
|
|
| No.route.to.host |
15
|
|
|
|
|
|
|
| temporarily.unavailable |
16
|
|
|
|
|
|
|
/x; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#=================================== |
19
|
|
|
|
|
|
|
sub perform_request { |
20
|
|
|
|
|
|
|
#=================================== |
21
|
|
|
|
|
|
|
my ( $self, $params ) = @_; |
22
|
|
|
|
|
|
|
my $uri = $self->build_uri($params); |
23
|
|
|
|
|
|
|
my $method = $params->{method}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %args; |
26
|
|
|
|
|
|
|
if ( defined $params->{data} ) { |
27
|
|
|
|
|
|
|
$args{content} = $params->{data}; |
28
|
|
|
|
|
|
|
$args{headers}{'Content-Type'} = $params->{mime_type}; |
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
|
|
|
1
|
0
|
3
|
local $_ = $_[2]; |
49
|
|
|
|
|
|
|
return |
50
|
1
|
0
|
|
|
|
11
|
/[Tt]imed out/ ? 'Timeout' |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
51
|
|
|
|
|
|
|
: /Unexpected end of stream/ ? 'ContentLength' |
52
|
|
|
|
|
|
|
: /$Cxn_Error/ ? 'Cxn' |
53
|
|
|
|
|
|
|
: 'Request'; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
#=================================== |
57
|
|
|
|
|
|
|
sub _build_handle { |
58
|
|
|
|
|
|
|
#=================================== |
59
|
0
|
|
|
0
|
|
|
my $self = shift; |
60
|
0
|
|
|
|
|
|
my %args = ( default_headers => $self->default_headers ); |
61
|
0
|
0
|
|
|
|
|
if ( $self->is_https ) { |
62
|
0
|
|
|
|
|
|
require IO::Socket::SSL; |
63
|
0
|
|
|
|
|
|
$args{SSL_options}{SSL_verify_mode} |
64
|
|
|
|
|
|
|
= IO::Socket::SSL::SSL_VERIFY_NONE(); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return HTTP::Tiny->new( %args, %{ $self->handle_args } ); |
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# ABSTRACT: A Cxn implementation which uses HTTP::Tiny |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=pod |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=encoding UTF-8 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Elasticsearch::Cxn::HTTPTiny - A Cxn implementation which uses HTTP::Tiny |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 VERSION |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
version 1.05 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 DESCRIPTION |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Provides the default HTTP Cxn class and is based on L<HTTP::Tiny>. |
91
|
|
|
|
|
|
|
The HTTP::Tiny backend is fast, uses pure Perl, support proxies and https |
92
|
|
|
|
|
|
|
and provides persistent connections. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This class does L<Elasticsearch::Role::Cxn::HTTP>, whose documentation |
95
|
|
|
|
|
|
|
provides more information, L<Elasticsearch::Role::Cxn> and |
96
|
|
|
|
|
|
|
L<Elasticsearch::Role::Is_Sync>. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 CONFIGURATION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 Inherited configuration |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
From L<Elasticsearch::Role::Cxn::HTTP> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=over |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item * L<node|Elasticsearch::Role::Cxn::HTTP/"node"> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * L<max_content_length|Elasticsearch::Role::Cxn::HTTP/"max_content_length"> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * L<deflate|Elasticsearch::Role::Cxn::HTTP/"deflate"> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
From L<Elasticsearch::Role::Cxn> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * L<request_timeout|Elasticsearch::Role::Cxn/"request_timeout"> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * L<ping_timeout|Elasticsearch::Role::Cxn/"ping_timeout"> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * L<dead_timeout|Elasticsearch::Role::Cxn/"dead_timeout"> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * L<max_dead_timeout|Elasticsearch::Role::Cxn/"max_dead_timeout"> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * L<sniff_request_timeout|Elasticsearch::Role::Cxn/"sniff_request_timeout"> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * L<sniff_timeout|Elasticsearch::Role::Cxn/"sniff_timeout"> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item * L<handle_args|Elasticsearch::Role::Cxn/"handle_args"> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 METHODS |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 C<perform_request()> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
($status,$body) = $self->perform_request({ |
139
|
|
|
|
|
|
|
# required |
140
|
|
|
|
|
|
|
method => 'GET|HEAD|POST|PUT|DELETE', |
141
|
|
|
|
|
|
|
path => '/path/of/request', |
142
|
|
|
|
|
|
|
qs => \%query_string_params, |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# optional |
145
|
|
|
|
|
|
|
data => $body_as_string, |
146
|
|
|
|
|
|
|
mime_type => 'application/json', |
147
|
|
|
|
|
|
|
timeout => $timeout |
148
|
|
|
|
|
|
|
}); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Sends the request to the associated Elasticsearch node and returns |
151
|
|
|
|
|
|
|
a C<$status> code and the decoded response C<$body>, or throws an |
152
|
|
|
|
|
|
|
error if the request failed. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 Inherited methods |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
From L<Elasticsearch::Role::Cxn::HTTP> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * L<scheme()|Elasticsearch::Role::Cxn::HTTP/"scheme()"> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * L<is_https()|Elasticsearch::Role::Cxn::HTTP/"is_https()"> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * L<userinfo()|Elasticsearch::Role::Cxn::HTTP/"userinfo()"> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * L<default_headers()|Elasticsearch::Role::Cxn::HTTP/"default_headers()"> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * L<max_content_length()|Elasticsearch::Role::Cxn::HTTP/"max_content_length()"> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * L<build_uri()|Elasticsearch::Role::Cxn::HTTP/"build_uri()"> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=back |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
From L<Elasticsearch::Role::Cxn> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=over |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * L<host()|Elasticsearch::Role::Cxn/"host()"> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * L<port()|Elasticsearch::Role::Cxn/"port()"> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * L<uri()|Elasticsearch::Role::Cxn/"uri()"> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * L<is_dead()|Elasticsearch::Role::Cxn/"is_dead()"> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * L<is_live()|Elasticsearch::Role::Cxn/"is_live()"> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * L<next_ping()|Elasticsearch::Role::Cxn/"next_ping()"> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * L<ping_failures()|Elasticsearch::Role::Cxn/"ping_failures()"> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item * L<mark_dead()|Elasticsearch::Role::Cxn/"mark_dead()"> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * L<mark_live()|Elasticsearch::Role::Cxn/"mark_live()"> |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item * L<force_ping()|Elasticsearch::Role::Cxn/"force_ping()"> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * L<pings_ok()|Elasticsearch::Role::Cxn/"pings_ok()"> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * L<sniff()|Elasticsearch::Role::Cxn/"sniff()"> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item * L<process_response()|Elasticsearch::Role::Cxn/"process_response()"> |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=back |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 SEE ALSO |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=over |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * L<Elasticsearch::Role::Cxn::HTTP> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item * L<Elasticsearch::Cxn::Hijk> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * L<Elasticsearch::Cxn::LWP> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item * L<Elasticsearch::Cxn::NetCurl> |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=back |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 AUTHOR |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Clinton Gormley <drtech@cpan.org> |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Elasticsearch BV. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
This is free software, licensed under: |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=cut |