ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-HTTP/HTTP.pm
(Generate patch)

Comparing AnyEvent-HTTP/HTTP.pm (file contents):
Revision 1.123 by root, Fri May 8 17:34:35 2015 UTC vs.
Revision 1.127 by root, Sun Aug 28 09:31:29 2016 UTC

46use AnyEvent::Util (); 46use AnyEvent::Util ();
47use AnyEvent::Handle (); 47use AnyEvent::Handle ();
48 48
49use base Exporter::; 49use base Exporter::;
50 50
51our $VERSION = 2.21; 51our $VERSION = 2.23;
52 52
53our @EXPORT = qw(http_get http_post http_head http_request); 53our @EXPORT = qw(http_get http_post http_head http_request);
54 54
55our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)"; 55our $USERAGENT = "Mozilla/5.0 (compatible; U; AnyEvent-HTTP/$VERSION; +http://software.schmorp.de/pkg/AnyEvent)";
56our $MAX_RECURSE = 10; 56our $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
895 # we give our best and fall back to URI if available. 895 # we give our best and fall back to URI if available.
896 if (exists $hdr{location}) { 896 if (exists $hdr{location}) {
897 my $loc = $hdr{location}; 897 my $loc = $hdr{location};
898 898
899 if ($loc =~ m%^//%) { # // 899 if ($loc =~ m%^//%) { # //
900 $loc = "$rscheme:$loc"; 900 $loc = "$uscheme:$loc";
901 901
902 } elsif ($loc eq "") { 902 } elsif ($loc eq "") {
903 $loc = $url; 903 $loc = $url;
904 904
905 } elsif ($loc !~ /^(?: $ | [^:\/?\#]+ : )/x) { # anything "simple" 905 } elsif ($loc !~ /^(?: $ | [^:\/?\#]+ : )/x) { # anything "simple"
906 $loc =~ s/^\.\/+//; 906 $loc =~ s/^\.\/+//;
907 907
908 if ($loc !~ m%^[.?#]%) { 908 if ($loc !~ m%^[.?#]%) {
909 my $prefix = "$rscheme://$uhost:$uport"; 909 my $prefix = "$uscheme://$uhost:$uport";
910 910
911 unless ($loc =~ s/^\///) { 911 unless ($loc =~ s/^\///) {
912 $prefix .= $upath; 912 $prefix .= $upath;
913 $prefix =~ s/\/[^\/]*$//; 913 $prefix =~ s/\/[^\/]*$//;
914 } 914 }
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 );
1461 or die "$file: $!"; 1461 or die "$file: $!";
1462 1462
1463 my %hdr; 1463 my %hdr;
1464 my $ofs = 0; 1464 my $ofs = 0;
1465 1465
1466 warn stat $fh;
1467 warn -s _;
1468 if (stat $fh and -s _) { 1466 if (stat $fh and -s _) {
1469 $ofs = -s _; 1467 $ofs = -s _;
1470 warn "-s is ", $ofs; 1468 warn "-s is ", $ofs;
1471 $hdr{"if-unmodified-since"} = AnyEvent::HTTP::format_date +(stat _)[9]; 1469 $hdr{"if-unmodified-since"} = AnyEvent::HTTP::format_date +(stat _)[9];
1472 $hdr{"range"} = "bytes=$ofs-"; 1470 $hdr{"range"} = "bytes=$ofs-";
1500 my (undef, $hdr) = @_; 1498 my (undef, $hdr) = @_;
1501 1499
1502 my $status = $hdr->{Status}; 1500 my $status = $hdr->{Status};
1503 1501
1504 if (my $time = AnyEvent::HTTP::parse_date $hdr->{"last-modified"}) { 1502 if (my $time = AnyEvent::HTTP::parse_date $hdr->{"last-modified"}) {
1505 utime $fh, $time, $time; 1503 utime $time, $time, $fh;
1506 } 1504 }
1507 1505
1508 if ($status == 200 || $status == 206 || $status == 416) { 1506 if ($status == 200 || $status == 206 || $status == 416) {
1509 # download ok || resume ok || file already fully downloaded 1507 # download ok || resume ok || file already fully downloaded
1510 $cb->(1, $hdr); 1508 $cb->(1, $hdr);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines