--- AnyEvent-HTTP/HTTP.pm 2011/07/27 16:11:55 1.109 +++ AnyEvent-HTTP/HTTP.pm 2013/05/17 07:19:23 1.116 @@ -48,7 +48,7 @@ use base Exporter::; -our $VERSION = '2.13'; +our $VERSION = '2.15'; our @EXPORT = qw(http_get http_post http_head http_request); @@ -125,7 +125,7 @@ =over 4 -=item 595 - errors during connection etsbalishment, proxy handshake. +=item 595 - errors during connection establishment, proxy handshake. =item 596 - errors during TLS negotiation, request sending and header processing. @@ -156,8 +156,8 @@ =item recurse => $count (default: $MAX_RECURSE) -Whether to recurse requests or not, e.g. on redirects, authentication -retries and so on, and how often to do so. +Whether to recurse requests or not, e.g. on redirects, authentication and +other retries and so on, and how often to do so. =item headers => hashref @@ -691,6 +691,44 @@ () } +our %IDEMPOTENT = ( + DELETE => 1, + GET => 1, + HEAD => 1, + OPTIONS => 1, + PUT => 1, + TRACE => 1, + + ACL => 1, + "BASELINE-CONTROL" => 1, + BIND => 1, + CHECKIN => 1, + CHECKOUT => 1, + COPY => 1, + LABEL => 1, + LINK => 1, + MERGE => 1, + MKACTIVITY => 1, + MKCALENDAR => 1, + MKCOL => 1, + MKREDIRECTREF => 1, + MKWORKSPACE => 1, + MOVE => 1, + ORDERPATCH => 1, + PROPFIND => 1, + PROPPATCH => 1, + REBIND => 1, + REPORT => 1, + SEARCH => 1, + UNBIND => 1, + UNCHECKOUT => 1, + UNLINK => 1, + UNLOCK => 1, + UPDATE => 1, + UPDATEREDIRECTREF => 1, + "VERSION-CONTROL" => 1, +); + sub http_request($$@) { my $cb = pop; my ($method, $url, %arg) = @_; @@ -775,7 +813,7 @@ $hdr{"content-length"} = length $arg{body} if length $arg{body} || $method ne "GET"; - my $idempotent = $method =~ /^(?:GET|HEAD|PUT|DELETE|OPTIONS|TRACE)$/; + my $idempotent = $IDEMPOTENT{$method}; # default value for keepalive is true iff the request is for an idempotent method my $persistent = exists $arg{persistent} ? !!$arg{persistent} : $idempotent; @@ -1052,8 +1090,9 @@ %state = (); $state{recurse} = http_request ( - $method => $url, + $method => $url, %arg, + recurse => $recurse - 1, keepalive => 0, sub { %state = (); @@ -1195,7 +1234,7 @@ To clear an already-set proxy, use C. -When AnyEvent::HTTP is laoded for the first time it will query the +When AnyEvent::HTTP is loaded for the first time it will query the default proxy from the operating system, currently by looking at C<$ENV{http_proxy>}. @@ -1217,11 +1256,12 @@ emptied. All other keys are hostnames or IP addresses pointing to hash-references. The key for these inner hash references is the server path for which this cookie is meant, and the values are again -hash-references. The keys of those hash-references is the cookie name, and +hash-references. Each key of those hash-references is a cookie name, and the value, you guessed it, is another hash-reference, this time with the key-value pairs from the cookie, except for C and C, which have been replaced by a C<_expires> key that contains the cookie -expiry timestamp. +expiry timestamp. Session cookies are indicated by not having an +C<_expires> key. Here is an example of a cookie jar with a single cookie, so you have a chance of understanding the above paragraph: @@ -1255,7 +1295,7 @@ =item $AnyEvent::HTTP::TIMEOUT -The default timeout for conenction operations (default: C<300>). +The default timeout for connection operations (default: C<300>). =item $AnyEvent::HTTP::USERAGENT @@ -1279,7 +1319,7 @@ =item $AnyEvent::HTTP::PERSISTENT_TIMEOUT -The time after which idle persistent conenctions get closed by +The time after which idle persistent connections get closed by AnyEvent::HTTP (default: C<3>). =item $AnyEvent::HTTP::ACTIVE @@ -1330,7 +1370,7 @@ for (0..11) { if ($m eq $month[$_]) { require Time::Local; - return Time::Local::timegm ($S, $M, $H, $d, $_, $y); + return eval { Time::Local::timegm ($S, $M, $H, $d, $_, $y) }; } }