GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
HTTP::AnyUA::Backend(3) User Contributed Perl Documentation HTTP::AnyUA::Backend(3)

HTTP::AnyUA::Backend - A base class for HTTP::AnyUA backends

version 0.904

    package HTTP::AnyUA::Backend::MyUserAgent;

    use parent 'HTTP::AnyUA::Backend';

    sub response_is_future { 0 }

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

        my $ua = $self->ua;

        # Here is where you transform the arguments into a request that $ua
        # understands, make the request against $ua and get a response, and
        # transform the response to the expected hashref form.

        my $resp = $ua->make_request();

        return $resp;
    }

    ### Non-blocking user agents are expected to return Future objects:

    use Future;

    sub response_is_future { 1 }

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

        my $ua = $self->ua;

        my $future = Future->new;

        # Again, this example glosses over transforming the request and response
        # to and from the actual user agent, but such details are the whole
        # point of a backend.

        $ua->nonblocking_callback(sub {
            my $resp = shift;

            if ($resp->{success}) {
                $future->done($resp);
            }
            else {
                $future->fail($resp);
            }
        });

        return $future;
    }

This module provides an interface for an HTTP::AnyUA "backend," which is an adapter that adds support for using a type of user agent with HTTP::AnyUA.

This class should not be instantiated directly, but it may be convenient for backend implementations to subclass it.

At its core, a backend simply takes a set of standard arguments that represent an HTTP request, transforms that request into a form understood by an underlying user agent, calls upon the user agent to make the request and get a response, and then transforms that response into a standard form. The standard forms for the request and response are based on HTTP::Tiny's arguments and return value to and from its request method.

Get the user agent that was passed to "new".

Get whether or not responses are Future objects. Default is false.

This may be overridden by implementations.

    $backend = HTTP::AnyUA::Backend::MyUserAgent->new($my_user_agent);

Construct a new backend.

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

Make a request, get a response.

This must be overridden by implementations.

  • "The Request" in HTTP::AnyUA - Explanation of the request arguments
  • "The Response" in HTTP::AnyUA - Explanation of the response

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.

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.

2019-03-17 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.