Furl
view release on metacpan or search on metacpan
### `$furl->put($url :Str, $headers :ArrayRef[Str], $content :Any)`
This is an easy-to-use alias to `request()`, sending the `PUT` method.
### `$furl->delete($url :Str, $headers :ArrayRef[Str] )`
This is an easy-to-use alias to `request()`, sending the `DELETE` method.
### `$furl->env_proxy()`
Loads proxy settings from `$ENV{HTTP_PROXY}` and `$ENV{NO_PROXY}`.
# TIPS
- [IO::Socket::SSL](https://metacpan.org/pod/IO%3A%3ASocket%3A%3ASSL) preloading
Furl interprets the `timeout` argument as the maximum time the module is permitted to spend before returning an error.
The module also lazy-loads [IO::Socket::SSL](https://metacpan.org/pod/IO%3A%3ASocket%3A%3ASSL) when an HTTPS request is being issued for the first time. Loading the module usually takes ~0.1 seconds.
The time spent for loading the SSL module may become an issue in case you want to impose a very small timeout value for connection establishment. In such case, users are advised to preload the SSL module explicitly.
lib/Furl.pm view on Meta::CPAN
=head3 C<< $furl->put($url :Str, $headers :ArrayRef[Str], $content :Any) >>
This is an easy-to-use alias to C<request()>, sending the C<PUT> method.
=head3 C<< $furl->delete($url :Str, $headers :ArrayRef[Str] ) >>
This is an easy-to-use alias to C<request()>, sending the C<DELETE> method.
=head3 C<< $furl->env_proxy() >>
Loads proxy settings from C<< $ENV{HTTP_PROXY} >> and C<< $ENV{NO_PROXY} >>.
=head1 TIPS
=over 4
=item L<IO::Socket::SSL> preloading
Furl interprets the C<timeout> argument as the maximum time the module is permitted to spend before returning an error.
The module also lazy-loads L<IO::Socket::SSL> when an HTTPS request is being issued for the first time. Loading the module usually takes ~0.1 seconds.
lib/Furl/HTTP.pm view on Meta::CPAN
# escape unsafe chars (defined by RFC 3986)
$s =~ s/ ([^A-Za-z0-9\-\._~]) / sprintf '%%%02X', ord $1 /xmsge;
}
push @params, "$k=$v";
}
return join( "&", @params );
}
sub env_proxy {
my $self = shift;
# Under CGI, bypass HTTP_PROXY as request sets it from Proxy header
# Note: This doesn't work on windows correctly.
local $ENV{HTTP_PROXY} if $ENV{REQUEST_METHOD};
$self->{proxy} = $ENV{http_proxy} || $ENV{HTTP_PROXY} || $self->{proxy};
$self->{no_proxy} = $ENV{NO_PROXY} || '';
$self;
}
sub request {
my $self = shift;
my %args = @_;
my $timeout_at = time + $self->{timeout};
t/100_low/08_proxy.t view on Meta::CPAN
}
sub test_agent () {
return Test::UserAgent->new(
env_proxy => 1,
keep_alive => 2,
parse_head => 0,
);
}
local $ENV{'HTTP_PROXY'} = '';
# Request target with non-default port
test_tcp(
client => sub {
my $proxy_port = shift;
my $httpd_port = $httpd->port;
client(
proxy => "http://127.0.0.1:$proxy_port",
request => "http://127.0.0.1:$httpd_port/foo",
t/100_low/32_proxy_auth.t view on Meta::CPAN
}
sub log {
my($self, $level, $prefix, $msg) = @_;
::note "$prefix: $msg" if $verbose;
}
}
my $via = "VIA!VIA!VIA!";
local $ENV{'HTTP_PROXY'} = '';
test_tcp(
client => sub {
my $proxy_port = shift;
test_tcp(
client => sub { # http client
my $httpd_port = shift;
for (1..3) { # run some times for testing keep-alive.
my $furl = Furl::HTTP->new(proxy => "http://dankogai:kogaidan\@127.0.0.1:$proxy_port");
my ( undef, $code, $msg, $headers, $content ) =
$furl->request(
t/100_low/39_httpoxy.t view on Meta::CPAN
plan tests => 8;
sub test_proxy {
my $expect = shift;
my $client = Furl::HTTP->new->env_proxy;
$client->{proxy};
}
undef $ENV{REQUEST_METHOD};
undef $ENV{HTTP_PROXY};
undef $ENV{http_proxy};
is test_proxy, '';
$ENV{REQUEST_METHOD} = 'GET';
undef $ENV{HTTP_PROXY};
undef $ENV{http_proxy};
is test_proxy, '';
SKIP: {
skip 'skip Windows', 1 if $^O eq 'MSWin32';
undef $ENV{REQUEST_METHOD};
$ENV{HTTP_PROXY} = 'http://proxy1.example.com';
undef $ENV{http_proxy};
is test_proxy, 'http://proxy1.example.com';
}
$ENV{REQUEST_METHOD} = 'GET';
$ENV{HTTP_PROXY} = 'http://proxy1.example.com';
undef $ENV{http_proxy};
is test_proxy, '';
undef $ENV{REQUEST_METHOD};
undef $ENV{HTTP_PROXY};
$ENV{http_proxy} = 'http://proxy2.example.com';
is test_proxy, 'http://proxy2.example.com';
SKIP: {
skip 'skip Windows', 1 if $^O eq 'MSWin32';
$ENV{REQUEST_METHOD} = 'GET';
undef $ENV{HTTP_PROXY};
$ENV{http_proxy} = 'http://proxy2.example.com';
is test_proxy, 'http://proxy2.example.com';
}
undef $ENV{REQUEST_METHOD};
$ENV{HTTP_PROXY} = 'http://proxy1.example.com';
$ENV{http_proxy} = 'http://proxy2.example.com';
is test_proxy, 'http://proxy2.example.com';
SKIP: {
skip 'skip Windows', 1 if $^O eq 'MSWin32';
$ENV{REQUEST_METHOD} = 'GET';
$ENV{HTTP_PROXY} = 'http://proxy1.example.com';
$ENV{http_proxy} = 'http://proxy2.example.com';
is test_proxy, 'http://proxy2.example.com';
}
use base qw/Exporter/;
use Test::More;
use Furl::HTTP;
use Fcntl qw(O_CREAT O_RDWR SEEK_SET);
our @EXPORT = qw/online skip_if_offline/;
my $orig = \&Furl::new;
sub wrapped_env_proxy {
my ($class, %args) = @_;
$args{proxy} = $ENV{HTTP_PROXY} if ($args{url}||'') !~ /^https?:\/\/\d+/;
return $orig->($class, %args);
};
{
no strict 'refs';
no warnings 'redefine';
*Furl::new = \&wrapped_env_proxy if $ENV{TEST_ENV_PROXY};
}
# taken from LWP::Online
my @RELIABLE_HTTP = (
( run in 1.548 second using v1.01-cache-2.11-cpan-71847e10f99 )