Skip to content

Commit

Permalink
fixed small redirect_to bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 15, 2011
1 parent 2e1ce67 commit dadc7d3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,7 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

1.99 2011-09-14 00:00:00
1.99 2011-09-15 00:00:00
- Improved documentation.
- Fixed small redirect_to bug. (judofyr, sri)

1.98 2011-09-14 00:00:00
- Removed Mojo::Server::FastCGI so it can be maintained as a separate
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Controller.pm
Expand Up @@ -191,7 +191,7 @@ sub redirect_to {
my $headers = $self->res->headers;
$headers->location($self->url_for(@_)->to_abs);
$headers->content_length(0);
$self->rendered(302);
$self->rendered($self->res->is_status_class(300) ? undef : 302);

return $self;
}
Expand Down
20 changes: 19 additions & 1 deletion t/mojolicious/lite_app.t
Expand Up @@ -10,7 +10,7 @@ BEGIN {
$ENV{MOJO_MODE} = 'development';
}

use Test::More tests => 896;
use Test::More tests => 902;

# Pollution
123 =~ m/(\d+)/;
Expand Down Expand Up @@ -578,6 +578,17 @@ get '/redirect_no_render' => sub {
shift->redirect_to('index', format => 'txt');
};

# GET /redirect_callback
get '/redirect_callback' => sub {
my $self = shift;
Mojo::IOLoop->defer(
sub {
$self->res->code(301);
$self->redirect_to('http://127.0.0.1/foo');
}
);
};

# GET /static_render
get '/static_render' => sub {
shift->render_static('hello.txt');
Expand Down Expand Up @@ -1552,6 +1563,13 @@ $t->get_ok('/redirect_no_render')->status_is(302)
->header_is('Content-Length' => 0)
->header_like(Location => qr/\/template.txt$/)->content_is('');

# GET /redirect_callback
$t->get_ok('/redirect_callback')->status_is(301)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->header_is('Content-Length' => 0)
->header_is(Location => 'http://127.0.0.1/foo');

# GET /static_render
$t->get_ok('/static_render')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
Expand Down

0 comments on commit dadc7d3

Please sign in to comment.