1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
package Future::HTTP::Tiny::Paranoid;
use strict;
use Future;
use HTTP::Tiny::Paranoid 0.07; # 0.04 had spurious CPAN tester failures
use Moo 2; # or Moo::Lax if you can't have Moo v2
use experimental 'signatures';
our $VERSION = '0.17';
extends 'Future::HTTP::Tiny';
has '+ua' => (
is => 'lazy',
default => sub { HTTP::Tiny::Paranoid->new( %{ $_[0]->_ua_args } ) }
);
=head1 NAME
Future::HTTP::Tiny::Paranoid - synchronous HTTP client with a Future interface
=head1 DESCRIPTION
This is the default backend. It is chosen if no supported event loop could
be detected. It will execute the requests synchronously as they are
made in C<< ->http_request >> .
=head1 Whitelist / Blacklist
You can set up the whitelist and blacklist through the global accessors:
# Allow access to localhost
HTTP::Tiny::Paranoid->whitelisted_hosts([ 'localhost', '127.0.0.1' ]);
# Deny access to localhost
HTTP::Tiny::Paranoid->blacklisted_hosts([ 'localhost', '127.0.0.1' ]);
=cut
=head1 METHODS
=head2 C<< Future::HTTP::Tiny::Paranoid->new() >>
my $ua = Future::HTTP::Tiny::Paranoid->new();
Creates a new instance of the HTTP client.
=head2 C<< $ua->is_async() >>
Returns false, because this backend is synchronous.
=head2 C<< $ua->http_get($url, %options) >>
$ua->http_get('http://example.com/',
headers => {
'Accept' => 'text/json',
},
)->then(sub {
my( $body, $headers ) = @_;
...
});
Retrieves the URL and returns the body and headers, like
the function in L<AnyEvent::HTTP>.
=head2 C<< $ua->http_head($url, %options) >>
$ua->http_head('http://example.com/',
headers => {
'Accept' => 'text/json',
},
)->then(sub {
my( $body, $headers ) = @_;
...
});
Retrieves the header of the URL and returns the headers,
like the function in L<AnyEvent::HTTP>.
=head2 C<< $ua->http_post($url, $body, %options) >>
$ua->http_post('http://example.com/api',
'{token:"my_json_token"}',
headers => {
'Accept' => 'text/json',
},
)->then(sub {
my( $body, $headers ) = @_;
...
});
Posts the content to the URL and returns the body and headers,
like the function in L<AnyEvent::HTTP>.
=head2 C<< $ua->http_request($method, $url, %options) >>
$ua->http_request('PUT' => 'http://example.com/api',
headers => {
'Accept' => 'text/json',
},
body => '{token:"my_json_token"}',
)->then(sub {
my( $body, $headers ) = @_;
...
});
Posts the content to the URL and returns the body and headers,
like the function in L<AnyEvent::HTTP>.
=head1 COMPATIBILITY
L<HTTP::Tiny> is a good backend because it is distributed with many versions
of Perl. The drawback is that not all versions of L<HTTP::Tiny> support all
features. The following features are unsupported on older versions of
L<HTTP::Tiny>:
=over 4
=item C<< ->{URL} >>
HTTP::Tiny versions before 0.018 didn't tell about 30x redirections.
=item C<< ->{redirects} >>
HTTP::Tiny versions before 0.058 didn't record the chain of redirects.
=back
=head1 SEE ALSO
L<Future>
L<AnyEvent::HTTP> for the details of the API
=head1 REPOSITORY
The public repository of this module is
L<https://github.com/Corion/future-http>.
=head1 SUPPORT
The public support forum of this module is
L<https://perlmonks.org/>.
=head1 BUG TRACKER
Please report bugs in this module via the RT CPAN bug queue at
L<https://rt.cpan.org/Public/Dist/Display.html?Name=Future-HTTP>
or via mail to L<future-http-Bugs@rt.cpan.org>.
=head1 AUTHOR
Max Maischein C<corion@cpan.org>
=head1 COPYRIGHT (c)
Copyright 2016-2024 by Max Maischein C<corion@cpan.org>.
=head1 LICENSE
This module is released under the same terms as Perl itself.
=cut
1;
|