… | |
… | |
46 | use AnyEvent::Util (); |
46 | use AnyEvent::Util (); |
47 | use AnyEvent::Handle (); |
47 | use AnyEvent::Handle (); |
48 | |
48 | |
49 | use base Exporter::; |
49 | use base Exporter::; |
50 | |
50 | |
51 | our $VERSION = 2.21; |
51 | our $VERSION = 2.22; |
52 | |
52 | |
53 | our @EXPORT = qw(http_get http_post http_head http_request); |
53 | our @EXPORT = qw(http_get http_post http_head http_request); |
54 | |
54 | |
55 | our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; |
55 | our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; |
56 | our $MAX_RECURSE = 10; |
56 | our $MAX_RECURSE = 10; |
… | |
… | |
773 | |
773 | |
774 | my $uport = $uscheme eq "http" ? 80 |
774 | my $uport = $uscheme eq "http" ? 80 |
775 | : $uscheme eq "https" ? 443 |
775 | : $uscheme eq "https" ? 443 |
776 | : return $cb->(undef, { @pseudo, Status => 599, Reason => "Only http and https URL schemes supported" }); |
776 | : return $cb->(undef, { @pseudo, Status => 599, Reason => "Only http and https URL schemes supported" }); |
777 | |
777 | |
778 | $uauthority =~ /^(?: .*\@ )? ([^\@:]+) (?: : (\d+) )?$/x |
778 | $uauthority =~ /^(?: .*\@ )? ([^\@]+?) (?: : (\d+) )?$/x |
779 | or return $cb->(undef, { @pseudo, Status => 599, Reason => "Unparsable URL" }); |
779 | or return $cb->(undef, { @pseudo, Status => 599, Reason => "Unparsable URL" }); |
780 | |
780 | |
781 | my $uhost = lc $1; |
781 | my $uhost = lc $1; |
782 | $uport = $2 if defined $2; |
782 | $uport = $2 if defined $2; |
783 | |
783 | |
… | |
… | |
1123 | _destroy_state %state; |
1123 | _destroy_state %state; |
1124 | |
1124 | |
1125 | %state = (); |
1125 | %state = (); |
1126 | $state{recurse} = |
1126 | $state{recurse} = |
1127 | http_request ( |
1127 | http_request ( |
1128 | $method => $url, |
1128 | $method => $url, |
1129 | %arg, |
1129 | %arg, |
1130 | recurse => $recurse - 1, |
1130 | recurse => $recurse - 1, |
1131 | keepalive => 0, |
1131 | persistent => 0, |
1132 | sub { |
1132 | sub { |
1133 | %state = (); |
1133 | %state = (); |
1134 | &$cb |
1134 | &$cb |
1135 | } |
1135 | } |
1136 | ); |
1136 | ); |