… | |
… | |
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; |
… | |
… | |
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 | } |