--- AnyEvent-HTTP/HTTP.pm 2008/06/09 13:02:13 1.19 +++ 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); @@ -95,10 +95,13 @@ response headers as second argument. All the headers in that hash are lowercased. In addition to the response -headers, the three "pseudo-headers" C, C and -C contain the three parts of the HTTP Status-Line of the same -name. If the server sends a header multiple lines, then their contents -will be joined together with C<\x00>. +headers, the "pseudo-headers" C, C and C +contain the three parts of the HTTP Status-Line of the same name. The +pseudo-header C contains the original URL (which can differ from the +requested URL when following redirects). + +If the server sends a header multiple lines, then their contents will be +joined together with C<\x00>. If an internal error occurs, such as not being able to resolve a hostname, then C<$data> will be C, C<< $headers->{Status} >> will be C<599> @@ -234,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; @@ -411,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]); } @@ -465,7 +475,8 @@ } sub http_post($$@) { - unshift @_, "POST", "body"; + my $url = shift; + unshift @_, "POST", $url, "body"; &http_request }