… | |
… | |
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.02'; |
51 | our $VERSION = '2.03'; |
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; |
… | |
… | |
529 | while ( |
529 | while ( |
530 | m{ |
530 | m{ |
531 | \G\s* |
531 | \G\s* |
532 | (?: |
532 | (?: |
533 | expires \s*=\s* ([A-Z][a-z][a-z]+,\ [^,;]+) |
533 | expires \s*=\s* ([A-Z][a-z][a-z]+,\ [^,;]+) |
534 | | ([^=;,[:space:]]+) (?: \s*=\s* (?: "((?:[^\\"]+|\\.)*)" | ([^=;,[:space:]]*) ) )? |
534 | | ([^=;,[:space:]]+) (?: \s*=\s* (?: "((?:[^\\"]+|\\.)*)" | ([^;,[:space:]]*) ) )? |
535 | ) |
535 | ) |
536 | }gcxsi |
536 | }gcxsi |
537 | ) { |
537 | ) { |
538 | my $name = $2; |
538 | my $name = $2; |
539 | my $value = $4; |
539 | my $value = $4; |
… | |
… | |
713 | |
713 | |
714 | my $proxy = $arg{proxy} || $PROXY; |
714 | my $proxy = $arg{proxy} || $PROXY; |
715 | my $timeout = $arg{timeout} || $TIMEOUT; |
715 | my $timeout = $arg{timeout} || $TIMEOUT; |
716 | |
716 | |
717 | my ($uscheme, $uauthority, $upath, $query, undef) = # ignore fragment |
717 | my ($uscheme, $uauthority, $upath, $query, undef) = # ignore fragment |
718 | $url =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:(\?[^#]*))?(?:#(.*))?|; |
718 | $url =~ m|^([^:]+):(?://([^/?#]*))?([^?#]*)(?:(\?[^#]*))?(?:#(.*))?$|; |
719 | |
719 | |
720 | $uscheme = lc $uscheme; |
720 | $uscheme = lc $uscheme; |
721 | |
721 | |
722 | my $uport = $uscheme eq "http" ? 80 |
722 | my $uport = $uscheme eq "http" ? 80 |
723 | : $uscheme eq "https" ? 443 |
723 | : $uscheme eq "https" ? 443 |
… | |
… | |
1333 | snippets. |
1333 | snippets. |
1334 | |
1334 | |
1335 | =head2 HTTP/1.1 FILE DOWNLOAD |
1335 | =head2 HTTP/1.1 FILE DOWNLOAD |
1336 | |
1336 | |
1337 | Downloading files with HTTP can be quite tricky, especially when something |
1337 | Downloading files with HTTP can be quite tricky, especially when something |
1338 | goes wrong and you want tor esume. |
1338 | goes wrong and you want to resume. |
1339 | |
1339 | |
1340 | Here is a function that initiates and resumes a download. It uses the |
1340 | Here is a function that initiates and resumes a download. It uses the |
1341 | last modified time to check for file content changes, and works with many |
1341 | last modified time to check for file content changes, and works with many |
1342 | HTTP/1.0 servers as well, and usually falls back to a complete re-download |
1342 | HTTP/1.0 servers as well, and usually falls back to a complete re-download |
1343 | on older servers. |
1343 | on older servers. |