Search...xn::LWP(3pm)

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

πŸ’– Search::Elasticsearch::Cxn::LWP β€” the LWP connection girly πŸ’–

okay bestie, gather round, because this is the Search::Elasticsearch::Cxn::LWP page from the perl manual (3pm, user contributed perl documentation, iykyk) and she is serving. ✨

🌸 NAME 🌸

Search::Elasticsearch::Cxn::LWP β€” literally a Cxn implementation that uses LWP. that's the whole name. that's the whole vibe. πŸ’…


✨ VERSION ✨

version 8.12 β€” yes she's on 8.12, keep up 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

So what she does: she provides an HTTP Cxn class, and she's based on LWP. The LWP backend is pure Perl and it keeps persistent connections alive. no cap. πŸ’–

This class does Search::Elasticsearch::Role::Cxn β€” and that documentation has more info if you're nosy (affectionate). She also does Search::Elasticsearch::Role::Is_Sync. 🌈


πŸŽ€ CONFIGURATION πŸŽ€

πŸ’œ Inherited configuration πŸ’œ

Inherited from Search::Elasticsearch::Role::Cxn, babes:

  • node
  • max_content_length
  • deflate
  • deflate
  • request_timeout
  • ping_timeout
  • dead_timeout
  • max_dead_timeout
  • sniff_request_timeout
  • sniff_timeout
  • handle_args
  • handle_args

(yes deflate and handle_args are each in there twice. not me editing the source, okay, that's just what the page says πŸ’€)

πŸ” SSL/TLS πŸ”

Search::Elasticsearch::Cxn::LWP uses IO::Socket::SSL to support HTTPS. By default, no validation of the remote host is performed. πŸ‘€

You can change that behaviour by passing the "ssl_options" parameter with any options that IO::Socket::SSL accepts. For instance, if you want to check that the remote host has a trusted certificate, and to dodge man-in-the-middle attacks, you could do the following:

use Search::Elasticsearch;

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

If the remote server cannot be verified, an Search::Elasticsearch::Error will be thrown β€” LWP does not allow us to detect that the connection error was due to invalid SSL. 😭 (it's giving "we tried our best")

And if you want your client to present its own certificate to the remote server, then use:

use Search::Elasticsearch;

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

slay. πŸ”₯


πŸ’… 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
});

She sends the request to the associated Elasticsearch node and returns a $status code and the decoded response $body. or she throws an error if the request failed. main character behaviour tbh πŸ‘‘

🧚 Inherited methods 🧚

Inherited 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()

look at that list. iconic. no notes. ✨


πŸ‘‘ SEE ALSO πŸ‘‘

  • Search::Elasticsearch::Role::Cxn
  • Search::Elasticsearch::Cxn::HTTPTiny
  • Search::Elasticsearch::Cxn::NetCurl

go read those too, bestie, they're all in the family 🫢


🌸 AUTHOR 🌸

Enrico Zimuel <enrico.zimuel@elastic.co> β€” thank u for ur service πŸŽ€


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

This is free software, licensed under:

The Apache License, Version 2.0, January 2004

and that's the page!! 🌈 footer tea for the very end: this was perl v5.38.2, dated 2024-02-04, and the page is Search...xn::LWP(3pm) (the truncated 3pm manual girlie). mwah, go forth and connect πŸ’‹πŸ’…βœ¨

πŸ“¦ where this page comes from