--- AnyEvent-HTTP/HTTP.pm 2008/07/02 01:30:33 1.24 +++ AnyEvent-HTTP/HTTP.pm 2008/07/21 05:42:07 1.25 @@ -357,7 +357,7 @@ # status line $state{handle}->push_read (line => qr/\015?\012/, sub { - $_[1] =~ /^HTTP\/([0-9\.]+) \s+ ([0-9]{3}) \s+ ([^\015\012]+)/ix + $_[1] =~ /^HTTP\/([0-9\.]+) \s+ ([0-9]{3}) (?: \s+ ([^\015\012]*) )?/ix or return (%state = (), $cb->(undef, { Status => 599, Reason => "invalid server response ($_[1])", URL => $url })); my %hdr = ( # response headers @@ -414,10 +414,20 @@ } } - # 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/% - if exists $_[1]{location}; + # microsoft and other shitheads don't give a shit for following standards, + # try to support some common forms of broken Location headers. + if ($_[1]{location} !~ /^(?: $ | [^:\/?\#]+ : )/x) { + $_[1]{location} =~ s/^\.\/+//; + + my $url = "$scheme://$uhost:$uport"; + + unless ($_[1]{location} =~ s/^\///) { + $url .= $upath; + $url =~ s/\/[^\/]*$//; + } + + $_[1]{location} = "$url/$_[1]{location}"; + } if ($_[1]{Status} =~ /^30[12]$/ && $recurse && $method ne "POST") { # apparently, mozilla et al. just change POST to GET here