| 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 | 30 | $OpenSearch::Client::Cxn::HTTPTiny::VERSION = '3.007011'; | |||||||||||||||||||||
| 25 | 30 | ▶ | use Moo; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 26 | 30 | with 'OpenSearch::Client::Role::Cxn', 'OpenSearch::Client::Role::Is_Sync'; | |||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | 30 | ▶ | use HTTP::Tiny 0.089 (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 29 | 30 | ▶ | use namespace::clean; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | 30 | 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 | 1 | ▶ | sub error_from_text { | ||||||||||||||||||||
|
Subroutine
error_from_text: called CC=5 SCAR=26.1
Pod
undocumented
| |||||||||||||||||||||||
| 69 | #=================================== | ||||||||||||||||||||||
| 70 | 1 | local $_ = $_[2]; | |||||||||||||||||||||
| 71 | return | ||||||||||||||||||||||
| 72 | 1 | ▶ | /[Tt]imed out/ ? 'Timeout' | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 73 | : /Unexpected end of stream/ ? 'ContentLength' | ||||||||||||||||||||||
| 74 | : /SSL connection failed/ ? 'SSL' | ||||||||||||||||||||||
| 75 | : /$Cxn_Error/ ? 'Cxn' | ||||||||||||||||||||||
| 76 | : 'Request'; | ||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | #=================================== | ||||||||||||||||||||||
| 80 | 0 | ▶ | sub _build_handle { | ||||||||||||||||||||
|
Subroutine
_build_handle: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||
| 81 | #=================================== | ||||||||||||||||||||||
| 82 | 0 | my $self = shift; | |||||||||||||||||||||
| 83 | 0 | my %args = ( default_headers => $self->default_headers ); | |||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $self->is_https ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 86 | $args{SSL_options} | ||||||||||||||||||||||
| 87 | 0 | ▶ | = $self->has_ssl_options | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 88 | ? $self->ssl_options | ||||||||||||||||||||||
| 89 | : { SSL_verify_mode => 0x01 }; | ||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | 0 | ▶ | $args{http_proxy} = $self->http_proxy if $self->has_http_proxy; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 93 | 0 | ▶ | $args{https_proxy} = $self->https_proxy if $self->has_https_proxy; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 94 | 0 | ▶ | $args{no_proxy} = $self->no_proxy if $self->has_no_proxy; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | 0 | return HTTP::Tiny->new( %args, %{ $self->handle_args } ); | |||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||
| 98 | |||||||||||||||||||||||
| 99 | 30 | 1; | |||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||||