On Fri Mar 21 19:53:51 2014, RWSTAUNER wrote:
Show quoted text> On Fri Mar 21 16:06:42 2014, blue wrote:
> > The created HTTP::Response should include any redirect chain.
> > Currently when doing:
> > my $res = AnyEvent::HTTP::Response->new(@_)->to_http_message;
> >
> > the HTTP::Response only includes the last part of the chain and gives
> > no indication there was even a redirect.
>
>
> I suspect that this is not an issue with this module as the conversion
> of the args doesn't do any sort of http interaction, it's just
> reformatting perl data structures.
Then it's not looking deep enough in the data structures. Because that information is given by both AnyEvent::HTTP and HTTP::Response. See below.
Show quoted text> How are you using this module? You likely need to disable redirection
> in your user agent if you want to see the redirects for yourself.
>
> For example:
>
> http_request $method, $url, recurse => 0;
> or
> $AnyEvent::HTTP::MAX_RECURSE = 0;
>
> The same functionality with LWP would be:
>
> LWP::UserAgent->new( max_redirect => 0 );
You're misunderstanding. I want the useragent to handle redirects automatically. BUT, both lwp's HTTP::Response and AnyEvent::HTTP will return the redirect chain in the response data structure for introspection.
So after a request that has followed at least one redirect, you can examine AnyEvent::HTTP's response headers to see the redirects. From it's docs:
The pseudo-header "Redirect" only exists when the request was a
result of an internal redirect. In that case it is an array
reference with the "($data, $headers)" from the redirect response.
Note that this response could in turn be the result of a redirect
itself, and "$headers->{Redirect}[1]{Redirect}" will then contain
the original response, and so on.
And when LWP follows a redirect, HTTP::Response will add the redirect chain into the _previous key in the response structure, and then provides the redirects() method to examine the redirect chain. See for yourself:
$ perl -MData::Dump -MLWP::UserAgent -E 'my $ua = LWP::UserAgent->new; my $res = $ua->get("
http://cpan.org"); dd $res'