--- AnyEvent-HTTP/HTTP.pm 2009/08/05 16:07:48 1.47 +++ AnyEvent-HTTP/HTTP.pm 2009/09/26 10:13:12 1.52 @@ -43,14 +43,14 @@ use Errno (); -use AnyEvent 4.8 (); +use AnyEvent 5.0 (); use AnyEvent::Util (); use AnyEvent::Socket (); use AnyEvent::Handle (); use base Exporter::; -our $VERSION = '1.41'; +our $VERSION = '1.43'; our @EXPORT = qw(http_get http_post http_head http_request); @@ -142,12 +142,15 @@ own C, C, C and C headers and will provide defaults for C and C (this can be suppressed by using C for these headers in which case they won't be -send at all). +sent at all). =item timeout => $seconds The time-out to use for various stages - each connect attempt will reset -the timeout, as will read or write activity. Default timeout is 5 minutes. +the timeout, as will read or write activity, i.e. this is not an overall +timeout. + +Default timeout is 5 minutes. =item proxy => [$host, $port[, $scheme]] or undef @@ -190,6 +193,15 @@ The default for this option is C, which could be interpreted as "give me the page, no matter what". +=item on_prepare => $callback->($fh) + +In rare cases you need to "tune" the socket before it is used to +connect (for exmaple, to bind it on a given IP address). This parameter +overrides the prepare callback passed to C +and behaves exactly the same way (e.g. it has to provide a +timeout). See the description for the C<$prepare_cb> argument of +C for details. + =item on_header => $callback->($headers) When specified, this callback will be called with the header hash as soon @@ -704,9 +716,7 @@ &$handle_actual_request; } - }, sub { - $timeout - }; + }, $arg{on_prepare} || sub { $timeout }; }; defined wantarray && AnyEvent::Util::guard { %state = () } @@ -737,7 +747,10 @@ =item AnyEvent::HTTP::set_proxy "proxy-url" Sets the default proxy server to use. The proxy-url must begin with a -string of the form C (optionally C). +string of the form C (optionally C), croaks +otherwise. + +To clear an already-set proxy, use C. =item $AnyEvent::HTTP::MAX_RECURSE @@ -768,11 +781,19 @@ =cut sub set_proxy($) { - $PROXY = [$2, $3 || 3128, $1] if $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix; + if (length $_[0]) { + $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix + or Carp::croak "$_[0]: invalid proxy URL"; + $PROXY = [$2, $3 || 3128, $1] + } else { + undef $PROXY; + } } # initialise proxy from environment -set_proxy $ENV{http_proxy}; +eval { + set_proxy $ENV{http_proxy}; +}; =head1 SEE ALSO