Skip to content

Commit

Permalink
fix PerlDancer#20 - redirect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fcuny committed Feb 16, 2010
1 parent fa7ba55 commit 180c018
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
7 changes: 2 additions & 5 deletions lib/Dancer/Helpers.pm
Expand Up @@ -71,11 +71,8 @@ sub error {
sub redirect {
my ($destination, $status) = @_;

Dancer::Response::set(
{ status => $status || 302,
headers => ['Location' => $destination],
}
);
Dancer::Response::status($status || 302);
Dancer::Response::headers('Location' => $destination);

halt; # w00t!
}
Expand Down
12 changes: 11 additions & 1 deletion lib/Dancer/Response.pm
Expand Up @@ -34,7 +34,17 @@ sub current {
}

# helpers for the route handlers
sub set { $CURRENT = shift }
sub set {
$CURRENT = shift;
#my $new_headers = shift;
#foreach my $keys (keys %$new_headers){
#next if $keys eq 'headers';
#}
#$CURRENT->{headers} = {%{$new_headers->{headers}}, %{$CURRENT->{headers}}};
#use YAML::Syck;
#print Dump $CURRENT;
#$CURRENT;
}
sub status { $CURRENT->{status} = shift }
sub content_type { $CURRENT->{content_type} = shift }
sub pass { $CURRENT->{pass} = 1 }
Expand Down
8 changes: 8 additions & 0 deletions t/03_route_handler/11_redirect.t
Expand Up @@ -15,6 +15,7 @@ is($res->{content}, "home",
"response content for / looks good");

$res = get_response_for_request(GET => '/bounce');

ok(defined($res), "got response for /bounce");
is($res->{status}, 302,
"response status is 302 for /bounce");
Expand All @@ -25,3 +26,10 @@ is($res->{content}, "home",
"response content for / looks good after a redirect");


get '/redirect' => sub { header 'X-Foo' => 'foo'; redirect '/'; };

$res = get_response_for_request(GET => '/redirect');
my %headers = @{$res->{headers}};
is $headers{'X-Foo'}, 'foo', 'header x-foo is set';
is $headers{'Location'}, '/', 'location is set to /';
clean_tmp_files();

0 comments on commit 180c018

Please sign in to comment.