… | |
… | |
41 | use strict; |
41 | use strict; |
42 | no warnings; |
42 | no warnings; |
43 | |
43 | |
44 | use Errno (); |
44 | use Errno (); |
45 | |
45 | |
46 | use AnyEvent 4.452 (); |
46 | use AnyEvent 4.8 (); |
47 | use AnyEvent::Util (); |
47 | use AnyEvent::Util (); |
48 | use AnyEvent::Socket (); |
48 | use AnyEvent::Socket (); |
49 | use AnyEvent::Handle (); |
49 | use AnyEvent::Handle (); |
50 | |
50 | |
51 | use base Exporter::; |
51 | use base Exporter::; |
52 | |
52 | |
53 | our $VERSION = '1.12'; |
53 | our $VERSION = '1.4'; |
54 | |
54 | |
55 | our @EXPORT = qw(http_get http_post http_head http_request); |
55 | our @EXPORT = qw(http_get http_post http_head http_request); |
56 | |
56 | |
57 | our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; |
57 | our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; |
58 | our $MAX_RECURSE = 10; |
58 | our $MAX_RECURSE = 10; |
… | |
… | |
419 | |
419 | |
420 | return unless $state{connect_guard}; |
420 | return unless $state{connect_guard}; |
421 | |
421 | |
422 | $state{connect_guard} = AnyEvent::Socket::tcp_connect $rhost, $rport, sub { |
422 | $state{connect_guard} = AnyEvent::Socket::tcp_connect $rhost, $rport, sub { |
423 | $state{fh} = shift |
423 | $state{fh} = shift |
|
|
424 | or do { |
|
|
425 | my $err = "$!"; |
|
|
426 | %state = (); |
424 | or return (%state = (), $cb->(undef, { Status => 599, Reason => "$!", URL => $url })); |
427 | return $cb->(undef, { Status => 599, Reason => $err, URL => $url }); |
|
|
428 | }; |
|
|
429 | |
425 | pop; # free memory, save a tree |
430 | pop; # free memory, save a tree |
426 | |
431 | |
427 | return unless delete $state{connect_guard}; |
432 | return unless delete $state{connect_guard}; |
428 | |
433 | |
429 | # get handle |
434 | # get handle |