Skip to content

Commit

Permalink
RedirectFilter should not append guid=ON when Location header already…
Browse files Browse the repository at this point in the history
… have guid param.
  • Loading branch information
walf443 committed Apr 8, 2010
1 parent a9ebf5f commit 9531cd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
9 changes: 7 additions & 2 deletions lib/Plack/Middleware/DoCoMoGUID/RedirectFilter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ sub call {

# Is there any case to using not match host?
if ( $uri->host eq ( $env->{HTTP_HOST} || $env->{SERVER_NAME} ) ) {
$uri->query_form(guid => 'ON', $uri->query_form);
Plack::Util::header_set($res->[1], 'location', $uri->as_string);
my %query_form = $uri->query_form;
if ( $query_form{guid} ) {
# no need to append param.
} else {
$uri->query_form(guid => 'ON', $uri->query_form);
Plack::Util::header_set($res->[1], 'location', $uri->as_string);
}
}
}

Expand Down
21 changes: 13 additions & 8 deletions t/01_redirect_filter.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@ subtest 'do filter case' => sub {
sub {
my $env = shift;
my $req = Plack::Request->new($env);
if ( $req->param('guid') ) {
return [200, [], ['found']];
} else {
return [302, [Location => $req->uri->as_string], []];
}
return [302, [Location => $req->uri->as_string], []];
};
};
$app->($env);
},
client => sub {
my $cb = shift;
my $req = HTTP::Request->new(GET => "http://localhost/hello?foo=bar");
my $res = $cb->($req);
is($res->header('location'), 'http://localhost/hello?guid=ON&foo=bar');
{
my $req = HTTP::Request->new(GET => "http://localhost/hello?foo=bar");
my $res = $cb->($req);
is($res->code, 302, 'redirect ok');
is($res->header('location'), 'http://localhost/hello?guid=ON&foo=bar', 'guid=ON should set');
}
{
my $req = HTTP::Request->new(GET => "http://localhost/hello?foo=bar&guid=FOO");
my $res = $cb->($req);
is($res->code, 302, 'redirect ok');
is($res->header('location'), 'http://localhost/hello?foo=bar&guid=FOO', 'should not append guid=ON');
}
},
);

Expand Down

0 comments on commit 9531cd4

Please sign in to comment.