• Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language
    Perl
  • License
    Other
  • Created about 14 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

pretty fast http client library for perl5

NAME

Furl - Lightning-fast URL fetcher

SYNOPSIS

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');

DESCRIPTION

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!

INTERFACE

Class Methods

Furl->new(%args | \%args) :Furl

Creates and returns a new Furl client with %args. Dies on errors.

%args might be:

  • agent :Str = "Furl/$VERSION"

  • timeout :Int = 10

  • max_redirects :Int = 7

  • capture_request :Bool = false

    If this parameter is true, Furl::HTTP captures raw request string. You can get it by $res->captured_req_headers and $res->captured_req_content.

  • proxy :Str

  • no_proxy :Str

  • headers :ArrayRef

  • cookie_jar :Object

    (EXPERIMENTAL)

    An instance of HTTP::CookieJar or equivalent class that supports the add and cookie_header methods

Instance Methods

$furl->request([$request,] %args) :Furl::Response

Sends an HTTP request to a specified URL and returns a instance of Furl::Response.

%args might be:

  • scheme :Str = "http"

    Protocol scheme. May be http or https.

  • host :Str

    Server host to connect.

    You must specify at least host or url.

  • port :Int = 80

    Server port to connect. The default is 80 on scheme => 'http', or 443 on scheme => 'https'.

  • path_query :Str = "/"

    Path and query to request.

  • url :Str

    URL to request.

    You can use url instead of scheme, host, port and path_query.

  • headers :ArrayRef

    HTTP request headers. e.g. headers => [ 'Accept-Encoding' => 'gzip' ].

  • content : Str | ArrayRef[Str] | HashRef[Str] | FileHandle

    Content to request.

If the number of arguments is an odd number, this method assumes that the first argument is an instance of HTTP::Request. Remaining arguments can be any of the previously describe values (but currently there's no way to really utilize them, so don't use it)

my $req = HTTP::Request->new(...);
my $res = $furl->request($req);

You can also specify an object other than HTTP::Request (e.g. Furl::Request), but the object must implement the following methods:

  • uri
  • method
  • content
  • headers

These must return the same type of values as their counterparts in HTTP::Request.

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.

$furl->env_proxy()

Loads proxy settings from $ENV{HTTP_PROXY} and $ENV{NO_PROXY}.

TIPS

  • IO::Socket::SSL 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 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.

FAQ

  • Does Furl depends on XS modules?

    No. Although some optional features require XS modules, basic features are available without XS modules.

    Note that Furl requires HTTP::Parser::XS, which seems an XS module but includes a pure Perl backend, HTTP::Parser::XS::PP.

  • I need more speed.

    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.

  • How do you use cookie_jar?

    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 = $f->request($req)->as_http_response;
      $res->request($req);
      $cookies->extract_cookies($res);
      # and use $res.
    
  • How do you limit the response content length?

    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;
          }
      );
    
  • How do you display the progress bar?

      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;
          }
      );
    
  • HTTPS requests claims warnings!

    When you make https requests, IO::Socket::SSL may complain about it like:

      *******************************************************************
       Using the default of SSL_verify_mode of SSL_VERIFY_NONE for client
       is depreciated! Please set SSL_verify_mode to SSL_VERIFY_PEER
       together with SSL_ca_file|SSL_ca_path for verification.
       If you really don't want to verify the certificate and keep the
       connection open to Man-In-The-Middle attacks please set
       SSL_verify_mode explicitly to SSL_VERIFY_NONE in your application.
      *******************************************************************
    

    You should set SSL_verify_mode explicitly with Furl's ssl_opts.

      use IO::Socket::SSL;
    
      my $ua = Furl->new(
          ssl_opts => {
              SSL_verify_mode => SSL_VERIFY_PEER(),
          },
      );
    

    See IO::Socket::SSL for details.

AUTHOR

Tokuhiro Matsuno [email protected]

Fuji, Goro (gfx)

THANKS TO

Kazuho Oku

mala

mattn

lestrrat

walf443

lestrrat

audreyt

SEE ALSO

LWP

IO::Socket::SSL

Furl::HTTP

Furl::Response

LICENSE

Copyright (C) Tokuhiro Matsuno.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

More Repositories

1

plenv

Perl binary manager
Shell
500
star
2

Amon

yet another web application framework
Perl
160
star
3

java-handbook

137
star
4

git-xlsx-textconv

Go
132
star
5

akaza

Yet another Japanese IME for IBus/Linux
Rust
127
star
6

Minilla

Authorizing tool for CPAN modules
Perl
97
star
7

Perl-Build

Perl
79
star
8

spring-vue-sample

Java
71
star
9

p6-Crust

PSGI library stack for Perl6
Raku
66
star
10

node-perl

Node perl wrapper
C++
63
star
11

toydi

Java
63
star
12

cpan-outdated

detect outdated CPAN modules
Perl
52
star
13

tora

Tora! Tora! Tora!
Perl
51
star
14

avans

Tiny thin web application framework for Java 8
Java
50
star
15

js-xlsx-demo

JavaScript
50
star
16

SQL-Maker

Perl
47
star
17

jawiki-kana-kanji-dict

Generate SKK/MeCab dictionary from Wikipedia(Japanese edition)
Python
40
star
18

node-mruby

C++
40
star
19

Daiku

Yet another build tool on Perl5
Perl
38
star
20

teng-handbook

Perl
38
star
21

mobirc

IRC Gateway for MobilePhone/iPhone/PC
JavaScript
33
star
22

Test-TCP

Test::TCP for perl
Perl
33
star
23

jsref

JavaScript
33
star
24

re2c-lemon-tutorial

C++
32
star
25

p5-router-simple

simple http router
Perl
32
star
26

tinyorm

Tiny O/R mapper for Java
Java
29
star
27

p5-psgiref

(DEPRECATED)just a prototype!
Perl
28
star
28

Web-Query

Perl
27
star
29

OrePAN

Perl
26
star
30

obsidian-2hop-links-plugin

TypeScript
26
star
31

optimize-perl-doc

how to optimize your perl code?
Perl
26
star
32

frepan

freshness mirror of cpan viewer
JavaScript
25
star
33

strftime-js

JavaScript
25
star
34

menta

General extlib/ for CGI applications.
Perl
25
star
35

PJP

Perl
24
star
36

micro_dispatcher.js

JavaScript
22
star
37

data-model-tutorial

the tutorial documents for Data::Model
Perl
22
star
38

OrePAN2

Perl
22
star
39

hoshipad

JavaScript
22
star
40

FormValidator-Lite

very lite and fast validation library for perl
Perl
21
star
41

go-examples

my Golang examples repo.
Go
21
star
42

THWebViewController

Minimalistic WebViewController
Objective-C
20
star
43

go-hsperfdata

Quite fast jps/jstat
Go
20
star
44

Test-Pretty

Perl
20
star
45

p5-http-server-fast

(DEPRECATED)
C++
18
star
46

p6-HTTP-Server-Tiny

Web application server for Perl6
Perl 6
18
star
47

gearman-stat.psgi

Display gearman stats.
18
star
48

visualwidth-js

JavaScript
18
star
49

Router-Boom

Perl
18
star
50

obsidian-pomodoro-plugin

TypeScript
17
star
51

Archer

Perl
17
star
52

nanobench

Tiny benchmarking framework for Java 7+
Java
17
star
53

nanowww

C++ lightweight, fast, portable HTTP client library
Perl
17
star
54

mouse

Moose minus the antlers
Perl
16
star
55

www-mobilecarrierjp

WWW::MobileCarrierJP
Perl
16
star
56

http-session

http session management library for perl
Perl
16
star
57

HTML-TreeBuilder-LibXML

drop-in-replacement for HTML::TreeBuilder::XPath
Perl
16
star
58

Tiffany

Template-For-All, Generic interface for perl template engines.
Perl
16
star
59

DBIx-Inspector

Perl
16
star
60

w3m

my private repo of w3m
C
15
star
61

File-Zglob

Perl
15
star
62

madeye

simple infrastructure monitoring tool
Perl
15
star
63

Smart-Args

the new args.pm!
Perl
15
star
64

Test-Kantan

Perl
14
star
65

Caroline

Yet another line editing library for Perl5
Perl
14
star
66

p5-net-drizzle

libdrizzle bindings for perl5
C
14
star
67

perl-echo-servers

C
14
star
68

gearman-starter.pl

bootstrap script for gearman worker
Perl
13
star
69

MySQL-BinLog

Perl
13
star
70

obsidian-stopwatch-plugin

TypeScript
13
star
71

MetaCPANExplorer

CSS
13
star
72

node-tcc

C++
13
star
73

HTML-Pictogram-MobileJp

[emoji:1] ใฟใŸใ„ใชใฎใ‚’ๅ‡ฆ็†ใงใใ‚‹ไบบ
Perl
13
star
74

App-watcher

Perl
13
star
75

tinyvalidator

Tiny validation library for Java 8
Java
13
star
76

Text-Markdown-Hoedown

Perl
13
star
77

java-samples

Java
12
star
78

nanotap

yet another tap header library
HTML
12
star
79

App-scan_prereqs_cpanfile

Scan prerequisite modules and generate CPANfile
Perl
12
star
80

MojaMoja

(PoC)yet another sinatra-ish framework built on CPAN modules
Perl
12
star
81

Test-SharedFork

Test::SharedFork
Perl
12
star
82

p5-cgi-emulate-psgi

CGI::Emulate::PSGI
Perl
11
star
83

p5-anyevent-mprpc

MessagePack RPC component for AnyEvent!
Perl
11
star
84

mRuby.pm

Perl
11
star
85

devel-bindpp

Devel::BindPP makes writing perl extension easily
C++
11
star
86

Test-Power

Perl
11
star
87

regexp-trie

Regexp::Trie for Java7
Java
11
star
88

Sub-Retry

Perl
11
star
89

blosxom.psgi

cho45 style blosxom thing for psgi. see http://coderepos.org/share/wiki/BlosxomClones
10
star
90

cgi-extlib-perl

General extlib/ for Perl CGI applications.
Perl
10
star
91

p5-module-install-forc

M::I extension for standalone C program/library
Perl
10
star
92

DBIx-Kohada

Perl
10
star
93

Amon2-Lite

Perl
10
star
94

autolink.js

JavaScript
10
star
95

Module-Spy

Perl
10
star
96

p6-WebSocket

Perl 6
10
star
97

Harriet

Perl
10
star
98

Cache-KyotoTycoon

KyotoTycoon client library for Perl5
Perl
10
star
99

mindcheese

Editable mindmap library written in TypeScript
TypeScript
10
star
100

Perl-Lexer

C
10
star