Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the WWW-Mechanize CPAN distribution.

Report information
The Basics
Id: 2834
Status: resolved
Priority: 0/
Queue: WWW-Mechanize

People
Owner: Nobody in particular
Requestors: corion [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.45
Fixed in: (no value)



Subject: Redirects do not update the URI
If an URL request gets redirected (302), $agent->uri() does return the original and not the redirected value. The attached lines need to be added to Mechanize.pm : # Keep track of the last uri redirected to : sub redirect_ok { $_[0]->{redirected_uri} = $_[1]->uri; 1 }; sub request { my $self = shift; my $request = shift; $request->header( Referer => $self->{last_uri} ) if $self->{last_uri}; while ( my($key,$value) = each %WWW::Mechanize::headers ) { $request->header( $key => $value ); } $self->{req} = $request; # added the line below $self->{redirected_uri} = $request->uri; $self->{res} = $self->SUPER::request( $request, @_ ); # These internal hash elements should be dropped in favor of # the accessors soon. -- 1/19/03 $self->{status} = $self->{res}->code; $self->{base} = $self->{res}->base; $self->{ct} = $self->{res}->content_type || ""; $self->{content} = $self->{res}->content; if ( $self->{res}->is_success ) { $self->{last_uri} = $self->{uri}; # commented out the line below #$self->{uri} = $request->uri; # added the line below $self->{uri} = $self->{redirected_uri}; } if ( $self->is_html ) { $self->{forms} = [ HTML::Form->parse($self->{content}, $self->{res}->base) ]; $self->{form} = @{$self->{forms}} ? $self->{forms}->[0] : undef; $self->{links} = $self->extract_links(); } return $self->{res}; }
From: "Max Maischein" <corion [...] corion.net>
To: <bug-WWW-Mechanize [...] rt.cpan.org>
Subject: Re: [cpan #2834] AutoReply: Redirects do not update the URI
Date: Sat, 21 Jun 2003 15:42:28 +0200
RT-Send-Cc:
In the tradition of fixing one bug by introducing another, my above fix has an error - the sequence of retrieving values is wrong. Correct is the below order for initializing the Referer header : if ( $self->{res}->is_success ) { #$self->{uri} = $request->uri; $self->{uri} = $self->{redirected_uri}; $self->{last_uri} = $self->{uri}; } Attached is a (revised) test program plus server that catches this error. -max

Message body is not shown because sender requested not to inline it.

Download referer-server
application/octet-stream 389b

Message body not shown because it is not plain text.

Date: Sat, 21 Jun 2003 19:04:14 -0500
To: bug-WWW-Mechanize [...] rt.cpan.org
From: Andy Lester <andy [...] petdance.com>
Subject: Re: [cpan #2834] Redirects do not update the URI
RT-Send-Cc:
I've made this change, and the following patch, in CVS. Remember, you can make CVS patches yourself now that you're on the project in Sourceforce. xoxo, Andy -- Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance
This introduced a bug in 0.48, which I've fixed in 0.49, where all redirects would occur, regardless of being OK to redirect.