HTTP::A...ddleware(3)

πŸ“¦ version 0.904, in alpine 3.24

πŸŽ€ NAME πŸŽ€

okay bestie, this is the User Contributed Perl Documentation for HTTP::AnyUA::Middleware, and it is literally a base class for HTTP::AnyUA middleware. πŸ’–


✨ VERSION ✨

version 0.904 β€” that's the version, no cap. 🫢


🌈 SYNOPSIS 🌈

package HTTP::AnyUA::Middleware::MyMiddleware;

use parent 'HTTP::AnyUA::Middleware';

sub request {
    my ($self, $method, $url, $args) = @_;

    # Maybe do something with the request args here.

    # Let backend handle the response:
    my $response = $self->backend->request($method, $url, $args);

    my $handle_response = sub {
        my $response = shift;

        # Maybe do something with the response here.

        return $response;
    };

    if ($self->response_is_future) {
        $response = $response->transform(
            done => $handle_response,
            fail => $handle_response,
        );
    }
    else {
        $response = $handle_response->($response);
    }

    return $response;
}

πŸ’… DESCRIPTION πŸ’…

This module gives you the interface for an HTTP::AnyUA β€œmiddleware,” which is a component that sits right between an HTTP::AnyUA object and the backend. And yes, that backend may in fact be another middleware β€” layers on layers, it's giving onion energy. πŸ§…βœ¨

The easiest way to use middleware is to use apply_middleware in HTTP::AnyUA. That's the main-character move.

The middleware mechanism can be used to munge or react to requests and responses to and from the backend user agent. Middlewares are a completely optional part of HTTP::AnyUA. They can be wrapped around each other to create multiple layers and interesting possibilities. The functionality provided by middleware may be alternative to features provided by some of the supported user agents, themselves, but implementing functionality on this layer makes it work for all the user agents. slay for consistency. πŸ’…


🧸 ATTRIBUTES 🧸

πŸͺž backend πŸͺž

Get the current backend that is wrapped. That's it, that's the vibe. 🌸

πŸͺž ua πŸͺž

Get the backend user agent. lowkey important. πŸ¦‹

πŸͺž response_is_future πŸͺž

Get whether or not responses are Future objects. Default is whatever the backend returns.

This may be overridden by implementations. πŸ‘‘


πŸ› οΈ METHODS πŸ› οΈ

🌱 new 🌱

$middleware = HTTP::AnyUA::Middleware::MyMiddleware->new($backend);
$middleware = HTTP::AnyUA::Middleware::MyMiddleware->new($backend, %args);

Construct a new middleware. fresh out the box. 🎁

πŸŒ€ init πŸŒ€

Called by the default constructor with the middleware arguments.

This may be overridden by implementations instead of the constructor. very customizable, very demure. πŸŽ€

🎁 wrap 🎁

$middleware = HTTP::AnyUA::Middleware::MyMiddleware->wrap($backend, %args);
$middleware->wrap($backend);

Construct a new middleware or, when called on an instance, set a new backend on an existing middleware. it's giving glow-up for backends. ✨

πŸ“¨ request πŸ“¨

$response = $middleware->request($method => $url, \%options);

Make a request, get a response. simple as that.

This should be overridden by implementations to do whatever they want with or to the request and/or response. go off, bestie. πŸ”₯


πŸ› BUGS πŸ›

Please report any bugs or feature requests on the bugtracker website: https://github.com/chazmcgarvey/HTTP-AnyUA/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. receipts help everyone. πŸ’–


πŸ‘‘ AUTHOR πŸ‘‘

Charles McGarvey <chazmcgarvey@brokenzipper.com>


This software is copyright (c) 2019 by Charles McGarvey.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt. πŸ’…


okay that's the whole page, bestie πŸ’– β€” this was perl v5.42.2, dated 2023-07-03, for the manual page HTTP::A...ddleware(3). byeee πŸŽ€

πŸ“¦ where this page comes from