Sometimes I want to test if my application sent the right redirect, but I don't want to follow it. It might be to a page that isn't accessible from my dev system, or is hosted by someone else and I don't want to hit it every time I run the test suite.
To do this with Test::WWW::Mechanize, I use this code:
my $mech = Test::WWW::Mechanize->new(autocheck => 0);
$mech->requests_redirectable([]); # don't follow redirects
$mech->get($uri);
is($mech->status, 302);
$mech->content_contains($url_to_redirect_to, 'sent to correct URL');
Another thing I want to check is if the request set a cookie. A simple way to do that:
my $resp = $mech->get($uri);
ok($resp->header('Set-Cookie'), 'has cookie header');
like($mech->cookie_jar->as_string(), qr/$COOKIE_NAME/,
'cookie was accepted');
Since the LWP cookie handling does the same checks that browsers do for domain and path, this can help catch problems with your cookie headers.
HTTP Redirect Headers (Score:2)
-Dom
Re:HTTP Redirect Headers (Score:1)
Re:HTTP Redirect Headers (Score:2)
-Dom
thanks (Score:1)