Search...TPTiny(3pm)

πŸ“¦
version 8.12 Β· 5 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Search::Elasticsearch::Cxn::HTTPTiny β€” bestie, it's a Cxn implementation that rides on HTTP::Tiny. That's the whole vibe. πŸ’…

This is a page from the User Contributed Perl Documentation, and it's giving very "let me explain my whole personality in one line."


🌸 VERSION 🌸

version 8.12 πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So this class is the default HTTP Cxn class, and it's built on top of HTTP::Tiny. No cap. ✨

The HTTP::Tiny backend? Fast. It uses pure Perl, it supports proxies and https, and it does persistent connections. It's giving low-maintenance-but-high-performance, honestly iconic. πŸ‘‘

This class does Search::Elasticsearch::Role::Cxn β€” go read that doc for more deets, it's the real main character β€” and it also does Search::Elasticsearch::Role::Is_Sync.


πŸ’– CONFIGURATION πŸ’–

🌈 Inherited configuration 🌈

Everything below comes from Search::Elasticsearch::Role::Cxn:

  • node
  • max_content_length
  • deflate
  • deflate
  • request_timeout
  • ping_timeout
  • dead_timeout
  • max_dead_timeout
  • sniff_request_timeout
  • sniff_timeout
  • handle_args
  • handle_args
Not me noticing deflate and handle_args are each listed twice πŸ’€ that's exactly what the original says, so that's exactly what I'm giving you. Fidelity is the moment. 🫢

πŸ”’ SSL/TLS πŸ”’

Search::Elasticsearch::Cxn::HTTPTiny uses IO::Socket::SSL to do HTTPS. And here's the tea: by default, no validation of the remote host is performed. Like, it's not checking anything. πŸ™ˆ

You can change that by passing the ssl_options parameter, filled with any options that IO::Socket::SSL accepts. Say you wanna check the remote host actually has a trusted certificate and dodge man-in-the-middle attacks? You'd do:

use Search::Elasticsearch;
use IO::Socket::SSL;

my $es = Search::Elasticsearch->new(
    nodes => [
        "https://node1.mydomain.com:9200",
        "https://node2.mydomain.com:9200",
    ],
    ssl_options => {
        SSL_verify_mode     => SSL_VERIFY_PEER,
        SSL_ca_file         => '/path/to/cacert.pem'
    }
);

And if the remote server can't be verified? An Search::Elasticsearch::Error will be thrown. Periodt.

Now if you want your client to show up with its own certificate β€” presenting itself to the remote server, main character energy β€” then you use:

use Search::Elasticsearch;
use IO::Socket::SSL;

my $es = Search::Elasticsearch->new(
    nodes => [
        "https://node1.mydomain.com:9200",
        "https://node2.mydomain.com:9200",
    ],
    ssl_options => {
        SSL_verify_mode     => SSL_VERIFY_PEER,
        SSL_use_cert        => 1,
        SSL_ca_file         => '/path/to/cacert.pem',
        SSL_cert_file       => '/path/to/client.pem',
        SSL_key_file        => '/path/to/client.pem',
    }
);

⭐ METHODS ⭐

πŸŽ€ perform_request() πŸŽ€

($status,$body) = $self->perform_request({
    # required
    method      => 'GET|HEAD|POST|PUT|DELETE',
    path        => '/path/of/request',
    qs          => \%query_string_params,

    # optional
    data        => $body_as_string,
    mime_type   => 'application/json',
    timeout     => $timeout
});

It sends the request off to the associated Elasticsearch node and hands you back a $status code plus the decoded response $body. And if the request flopped? It throws an error. No gentle letdown, just an error. 😭

🌸 Inherited methods 🌸

These all come from Search::Elasticsearch::Role::Cxn:

  • scheme()
  • is_https()
  • userinfo()
  • default_headers()
  • max_content_length()
  • build_uri()
  • host()
  • port()
  • uri()
  • is_dead()
  • is_live()
  • next_ping()
  • ping_failures()
  • mark_dead()
  • mark_live()
  • force_ping()
  • pings_ok()
  • sniff()
  • process_response()

πŸ‘€ SEE ALSO πŸ‘€

  • Search::Elasticsearch::Role::Cxn
  • Search::Elasticsearch::Cxn::LWP
  • Search::Elasticsearch::Cxn::NetCurl

iykyk, go read them, they're all part of the same little friend group. 🫢


πŸ’œ AUTHOR πŸ’œ

Enrico Zimuel <enrico.zimuel@elastic.co> β€” the icon who wrote this. πŸ‘‘


This software is Copyright (c) 2024 by Elasticsearch BV.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004

Okay bestie that's the whole page!! πŸ’– This beauty is perl v5.38.2, dated 2024-02-04, and it lives in the User Contributed Perl Documentation section. Slay, go make some requests. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from