--- AnyEvent-HTTP/HTTP.pm 2008/06/09 13:04:23 1.20 +++ AnyEvent-HTTP/HTTP.pm 2008/07/02 01:23:41 1.23 @@ -50,7 +50,7 @@ use base Exporter::; -our $VERSION = '1.01'; +our $VERSION = '1.03'; our @EXPORT = qw(http_get http_post http_head http_request); @@ -237,7 +237,7 @@ } } - my $recurse = exists $arg{recurse} ? $arg{recurse} : $MAX_RECURSE; + my $recurse = exists $arg{recurse} ? delete $arg{recurse} : $MAX_RECURSE; return $cb->(undef, { Status => 599, Reason => "recursion limit reached", URL => $url }) if $recurse < 0; @@ -414,12 +414,19 @@ } } - if ($_[1]{Status} =~ /^30[12]$/ && $recurse) { + if ($_[1]{Status} =~ /^30[12]$/ && $recurse && $method ne "POST") { # microsoft and other assholes don't give a shit for following standards, # try to support a common form of broken Location header. $_[1]{location} =~ s%^/%$scheme://$uhost:$uport/%; + # apparently, mozilla et al. just change POST to GET here + # more research is needed before we do the same + http_request ($method, $_[1]{location}, %arg, recurse => $recurse - 1, $cb); + } elsif ($_[1]{Status} == 303 && $recurse) { + $_[1]{location} =~ s%^/%$scheme://$uhost:$uport/%; + + http_request (GET => $_[1]{location}, %arg, recurse => $recurse - 1, $cb); } else { $cb->($_[0], $_[1]); } @@ -468,7 +475,8 @@ } sub http_post($$@) { - unshift @_, "POST", "body"; + my $url = shift; + unshift @_, "POST", $url, "body"; &http_request }