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.95 by root, Wed Jan 12 03:30:05 2011 UTC vs.
Revision 1.102 by root, Sat Feb 19 06:46:14 2011 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.02'; 51our $VERSION = '2.04';
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;
179 179
180Default timeout is 5 minutes. 180Default timeout is 5 minutes.
181 181
182=item proxy => [$host, $port[, $scheme]] or undef 182=item proxy => [$host, $port[, $scheme]] or undef
183 183
184Use the given http proxy for all requests. If not specified, then the 184Use the given http proxy for all requests, or no proxy if C<undef> is
185default proxy (as specified by C<$ENV{http_proxy}>) is used. 185used.
186 186
187C<$scheme> must be either missing or must be C<http> for HTTP. 187C<$scheme> must be either missing or must be C<http> for HTTP.
188
189If not specified, then the default proxy is used (see
190C<AnyEvent::HTTP::set_proxy>).
188 191
189=item body => $string 192=item body => $string
190 193
191The request body, usually empty. Will be sent as-is (future versions of 194The request body, usually empty. Will be sent as-is (future versions of
192this module might offer more options). 195this module might offer more options).
529 while ( 532 while (
530 m{ 533 m{
531 \G\s* 534 \G\s*
532 (?: 535 (?:
533 expires \s*=\s* ([A-Z][a-z][a-z]+,\ [^,;]+) 536 expires \s*=\s* ([A-Z][a-z][a-z]+,\ [^,;]+)
534 | ([^=;,[:space:]]+) (?: \s*=\s* (?: "((?:[^\\"]+|\\.)*)" | ([^=;,[:space:]]*) ) )? 537 | ([^=;,[:space:]]+) (?: \s*=\s* (?: "((?:[^\\"]+|\\.)*)" | ([^;,[:space:]]*) ) )?
535 ) 538 )
536 }gcxsi 539 }gcxsi
537 ) { 540 ) {
538 my $name = $2; 541 my $name = $2;
539 my $value = $4; 542 my $value = $4;
709 my $recurse = exists $arg{recurse} ? delete $arg{recurse} : $MAX_RECURSE; 712 my $recurse = exists $arg{recurse} ? delete $arg{recurse} : $MAX_RECURSE;
710 713
711 return $cb->(undef, { @pseudo, Status => 599, Reason => "Too many redirections" }) 714 return $cb->(undef, { @pseudo, Status => 599, Reason => "Too many redirections" })
712 if $recurse < 0; 715 if $recurse < 0;
713 716
714 my $proxy = $arg{proxy} || $PROXY; 717 my $proxy = exists $arg{proxy} ? $arg{proxy} : $PROXY;
715 my $timeout = $arg{timeout} || $TIMEOUT; 718 my $timeout = $arg{timeout} || $TIMEOUT;
716 719
717 my ($uscheme, $uauthority, $upath, $query, undef) = # ignore fragment 720 my ($uscheme, $uauthority, $upath, $query, undef) = # ignore fragment
718 $url =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:(\?[^#]*))?(?:#(.*))?|; 721 $url =~ m|^([^:]+):(?://([^/?#]*))?([^?#]*)(?:(\?[^#]*))?(?:#(.*))?$|;
719 722
720 $uscheme = lc $uscheme; 723 $uscheme = lc $uscheme;
721 724
722 my $uport = $uscheme eq "http" ? 80 725 my $uport = $uscheme eq "http" ? 80
723 : $uscheme eq "https" ? 443 726 : $uscheme eq "https" ? 443
1172Sets the default proxy server to use. The proxy-url must begin with a 1175Sets the default proxy server to use. The proxy-url must begin with a
1173string of the form C<http://host:port>, croaks otherwise. 1176string of the form C<http://host:port>, croaks otherwise.
1174 1177
1175To clear an already-set proxy, use C<undef>. 1178To clear an already-set proxy, use C<undef>.
1176 1179
1180When AnyEvent::HTTP is laoded for the first time it will query the
1181default proxy from the operating system, currently by looking at
1182C<$ENV{http_proxy>}.
1183
1177=item AnyEvent::HTTP::cookie_jar_expire $jar[, $session_end] 1184=item AnyEvent::HTTP::cookie_jar_expire $jar[, $session_end]
1178 1185
1179Remove all cookies from the cookie jar that have been expired. If 1186Remove all cookies from the cookie jar that have been expired. If
1180C<$session_end> is given and true, then additionally remove all session 1187C<$session_end> is given and true, then additionally remove all session
1181cookies. 1188cookies.
1332This section contaisn some more elaborate "real-world" examples or code 1339This section contaisn some more elaborate "real-world" examples or code
1333snippets. 1340snippets.
1334 1341
1335=head2 HTTP/1.1 FILE DOWNLOAD 1342=head2 HTTP/1.1 FILE DOWNLOAD
1336 1343
1337Downloading files with HTTP cna be quite tricky, especially when something 1344Downloading files with HTTP can be quite tricky, especially when something
1338goes wrong and you want tor esume. 1345goes wrong and you want to resume.
1339 1346
1340Here is a function that initiates and resumes a download. It uses the 1347Here is a function that initiates and resumes a download. It uses the
1341last modified time to check for file content changes, and works with many 1348last modified time to check for file content changes, and works with many
1342HTTP/1.0 servers as well, and usually falls back to a complete re-download 1349HTTP/1.0 servers as well, and usually falls back to a complete re-download
1343on older servers. 1350on older servers.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines