Furl - Lightning-fast URL fetcher
use Furl; my $furl = Furl->new( agent => 'MyGreatUA/2.0', timeout => 10, ); my $res = $furl->get('http://example.com/'); die $res->status_line unless $res->is_success; print $res->content; my $res = $furl->post( 'http://example.com/', # URL [...], # headers [ foo => 'bar' ], # form data (HashRef/FileHandle are also okay) ); # Accept-Encoding is supported but optional $furl = Furl->new( headers => [ 'Accept-Encoding' => 'gzip' ], ); my $body = $furl->get('http://example.com/some/compressed');
Furl is yet another HTTP client library. LWP is the de facto standard HTTP client for Perl5, but it is too slow for some critical jobs, and too complex for weekend hacking. Furl resolves these issues. Enjoy it!
This library is an alpha software. Any API may change without notice.
Furl->new(%args | \%args) :Furl
Creates and returns a new Furl client with %args. Dies on errors.
%args might be:
$furl->request(%args) :Furl::Response
Sends an HTTP request to a specified URL and returns a instance of Furl::Response.
Protocol scheme. May be http or https.
http
https
Server host to connect.
You must specify at least host or url.
host
url
Server port to connect. The default is 80 on scheme => 'http', or 443 on scheme => 'https'.
scheme => 'http'
scheme => 'https'
Path and query to request.
URL to request.
You can use url instead of scheme, host, port and path_query.
scheme
port
path_query
HTTP request headers. e.g. headers => [ 'Accept-Encoding' => 'gzip' ].
headers => [ 'Accept-Encoding' => 'gzip' ]
Content to request.
You must encode all the queries or this method will die, saying Wide character in ....
Wide character in ...
$furl->get($url :Str, $headers :ArrayRef[Str] )
This is an easy-to-use alias to request(), sending the GET method.
request()
GET
$furl->head($url :Str, $headers :ArrayRef[Str] )
This is an easy-to-use alias to request(), sending the HEAD method.
HEAD
$furl->post($url :Str, $headers :ArrayRef[Str], $content :Any)
This is an easy-to-use alias to request(), sending the POST method.
POST
$furl->put($url :Str, $headers :ArrayRef[Str], $content :Any)
This is an easy-to-use alias to request(), sending the PUT method.
PUT
$furl->delete($url :Str, $headers :ArrayRef[Str] )
This is an easy-to-use alias to request(), sending the DELETE method.
DELETE
$furl->request_with_http_request($req :HTTP::Request)
This is an easy-to-use alias to request() with an instance of HTTP::Request.
HTTP::Request
$furl->env_proxy()
Loads proxy settings from $ENV{HTTP_PROXY} and $ENV{NO_PROXY}.
$ENV{HTTP_PROXY}
$ENV{NO_PROXY}
See Furl::HTTP, which provides the low level interface of Furl. It is faster than Furl.pm since Furl::HTTP does not create response objects.
Furl.pm
Furl does not directly support the cookie_jar option available in LWP. You can use HTTP::Cookies, HTTP::Request, HTTP::Response like following.
my $f = Furl->new(); my $cookies = HTTP::Cookies->new(); my $req = HTTP::Request->new(...); $cookies->add_cookie_header($req); my $res = H$f->request_with_http_request($req)->as_http_response; $cookies->extract_cookies($res); # and use $res.
You can limit the content length by callback function.
my $f = Furl->new(); my $content = ''; my $limit = 1_000_000; my %special_headers = ('content-length' => undef); my $res = $f->request( method => 'GET', url => $url, special_headers => \%special_headers, write_code => sub { my ( $status, $msg, $headers, $buf ) = @_; if (($special_headers{'content-length'}||0) > $limit || length($content) > $limit) { die "over limit: $limit"; } $content .= $buf; } );
my $bar = Term::ProgressBar->new({count => 1024, ETA => 'linear'}); $bar->minor(0); $bar->max_update_rate(1); my $f = Furl->new(); my $content = ''; my %special_headers = ('content-length' => undef);; my $did_set_target = 0; my $received_size = 0; my $next_update = 0; $f->request( method => 'GET', url => $url, special_headers => \%special_headers, write_code => sub { my ( $status, $msg, $headers, $buf ) = @_; unless ($did_set_target) { if ( my $cl = $special_headers{'content-length'} ) { $bar->target($cl); $did_set_target++; } else { $bar->target( $received_size + 2 * length($buf) ); } } $received_size += length($buf); $content .= $buf; $next_update = $bar->update($received_size) if $received_size >= $next_update; } );
Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM>
Fuji, Goro (gfx)
Kazuho Oku
mala
mattn
lestrrat
walf443
LWP
Furl::HTTP
Furl::Response
Copyright (C) Tokuhiro Matsuno.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Furl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Furl
CPAN shell
perl -MCPAN -e shell install Furl
For more information on module installation, please visit the detailed CPAN module installation guide.