| 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 | 29 | $Search::Elasticsearch::Cxn::HTTPTiny::VERSION = '8.12'; | |||||||||||||||||||||||||||
| 20 | 29 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 29 | with 'Search::Elasticsearch::Role::Cxn', 'Search::Elasticsearch::Role::Is_Sync'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 29 | ▶ | use HTTP::Tiny 0.076 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 29 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 29 | 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 | 1 | ▶ | sub error_from_text { | ||||||||||||||||||||||||||
|
Subroutine
error_from_text: called CC=5 SCAR=26.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | #=================================== | ||||||||||||||||||||||||||||
| 65 | 1 | local $_ = $_[2]; | |||||||||||||||||||||||||||
| 66 | return | ||||||||||||||||||||||||||||
| 67 | 1 | ▶ | /[Tt]imed out/ ? 'Timeout' | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 68 | : /Unexpected end of stream/ ? 'ContentLength' | ||||||||||||||||||||||||||||
| 69 | : /SSL connection failed/ ? 'SSL' | ||||||||||||||||||||||||||||
| 70 | : /$Cxn_Error/ ? 'Cxn' | ||||||||||||||||||||||||||||
| 71 | : 'Request'; | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | #=================================== | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub _build_handle { | ||||||||||||||||||||||||||
|
Subroutine
_build_handle: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 76 | #=================================== | ||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 0 | my %args = ( default_headers => $self->default_headers ); | |||||||||||||||||||||||||||
| 79 | 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
| |||||||||||||||||||||||||||||
| 80 | 0 | $args{SSL_options} = $self->ssl_options; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( $args{SSL_options}{SSL_verify_mode} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $args{verify_ssl} = 1; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | return HTTP::Tiny->new( %args, %{ $self->handle_args } ); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 29 | 1; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # ABSTRACT: A Cxn implementation which uses HTTP::Tiny | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | __END__ | ||||||||||||||||||||||||||||