Furl::HTTP(3pm) | User Contributed Perl Documentation | Furl::HTTP(3pm) |
Furl::HTTP - Low level interface to Furl
use Furl; my $furl = Furl::HTTP->new( agent => 'MyGreatUA/2.0', timeout => 10, ); my ($minor_version, $code, $msg, $headers, $body) = $furl->request( method => 'GET', host => 'example.com', port => 80, path_query => '/' ); # or # 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 Perl 5, but it is too slow for some critical jobs, and too complex for weekend hacking. Furl resolves these issues. Enjoy it!
"Furl::HTTP->new(%args | \%args) :Furl"
Creates and returns a new Furl client with %args. Dies on errors.
%args might be:
This option allows HEADERS_NONE or HEADERS_AS_ARRAYREF.
HEADERS_AS_ARRAYREF is a default value. This makes $headers as ArrayRef.
HEADERS_NONE makes $headers as undef. Furl does not return parsing result of headers. You should take needed headers from special_headers.
You may not customize this variable otherwise to use Coro. This attribute requires a duck type object. It has two methods, "$obj->steal($host, $port" and "$obj->push($host, $port, $sock)".
A callback function to customize name resolution. Takes two arguments: ($hostname, $timeout_in_seconds). If omitted, Furl calls Socket::inet_aton.
for example:
use IO::Socket::SSL; my $ua = Furl::HTTP->new( ssl_opts => { SSL_verify_mode => SSL_VERIFY_PEER(), }, });
See IO::Socket::SSL for details.
"$furl->request(%args) :($protocol_minor_version, $code, $msg, \@headers, $body)"
Sends an HTTP request to a specified URL and returns a protocol minor version, status code, status message, response headers, response body respectively.
%args might be:
You must specify at least "host" or "url".
You can use "url" instead of "scheme", "host", "port" and "path_query".
It's like a ":content_file" in LWP::UserAgent.
It's like a ":content_cb" in LWP::UserAgent.
The "request()" method assumes the first argument to be an instance of "HTTP::Request" if the arguments are an odd number:
my $req = HTTP::Request->new(...); my @res = $furl->request($req); # allowed
You must encode all the queries or this method will die, saying "Wide character in ...".
"$furl->get($url :Str, $headers :ArrayRef[Str] )"
This is an easy-to-use alias to "request()", sending the "GET" method.
"$furl->head($url :Str, $headers :ArrayRef[Str] )"
This is an easy-to-use alias to "request()", sending the "HEAD" method.
"$furl->post($url :Str, $headers :ArrayRef[Str], $content :Any)"
This is an easy-to-use alias to "request()", sending the "POST" method.
"$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.
And other operating systems will be supported if you send a patch.
First, you cannot send chunked requests unless the peer server at the other end of the established TCP connection is known to be a HTTP/1.1 server.
Second, HTTP/1.1 servers disconnect their persistent connection quite quickly (compared to the time they wait for the first request), so it is not a good idea to post non-idempotent requests (e.g. POST, PUT, etc.) as a succeeding request over persistent connections.
These facts together makes using chunked requests virtually impossible (unless you _know_ that the server supports HTTP/1.1), and this is why we decided that supporting the feature is NOT of high priority.
my $fh = IO::Callback->new( '<', sub { my $x = shift @data; $x ? "-$x" : undef; } ); my ( $code, $msg, $headers, $content ) = $furl->put( "http://127.0.0.1:$port/", [ 'Content-Length' => $len ], $fh, );
use HTTP::Request::Common; my $furl = Furl->new(); $req = POST 'http://www.perl.org/survey.cgi', Content_Type => 'form-data', Content => [ name => 'Hiromu Tokunaga', email => 'tokuhirom@example.com', gender => 'F', born => '1978', init => ["$ENV{HOME}/.profile"], ]; $furl->request($req);
Native multipart/form-data support for Furl is available if you can send a patch for me.
RFC 2616 section 9.4 says:
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.
Some web applications, however, returns message bodies on the HEAD method, which might confuse "Keep-Alive" processes, so Furl closes connection in such cases.
Anyway, the HEAD method is not so useful nowadays. The GET method and "If-Modified-Since" are more suitable to cache HTTP contents.
use Net::DNS::Lite qw(); my $furl = Furl->new( timeout => $my_timeout_in_seconds, inet_aton => sub { Net::DNS::Lite::inet_aton(@_) }, );
If you want to send HTTP requests to a dedicated server (or a UNIX socket), you should use the get_address callback to designate the peer to which Furl should connect as sockaddr.
The example below sends all requests to 127.0.0.1:8080.
my $ua = Furl::HTTP->new( get_address => sub { my ($host, $port, $timeout) = @_; pack_sockaddr_in(8080, inet_aton("127.0.0.1")); }, ); my ($minor_version, $code, $msg, $headers, $body) = $furl->request( url => 'http://example.com/foo', method => 'GET' );
- AnyEvent::Furl? - ipv6 support - better docs for NO_PROXY
This feature requires Net::IDN::Encode.
This feature requires IO::Socket::SSL.
This feature requires Compress::Raw::Zlib.
To setup your environment:
$ git clone http://github.com/tokuhirom/Furl.git $ cd Furl
To get picohttpparser:
$ git submodule init $ git submodule update $ perl Makefile.PL $ make $ sudo make install
Please send the pull request via <http://github.com/tokuhirom/Furl/>.
LWP
HTTP specs: <http://www.w3.org/Protocols/HTTP/1.0/spec.html> <http://www.w3.org/Protocols/HTTP/1.1/spec.html>
Copyright (C) Tokuhiro Matsuno.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2019-03-21 | perl v5.28.1 |