Permalink
Browse files

http headers as array ref

  • Loading branch information...
1 parent df5c586 commit f6c7c15376ec5dda5907f51439293eef476c1e04 Zbigniew Lukasiak committed May 23, 2011
Showing with 13 additions and 7 deletions.
  1. +2 −0 Changes
  2. +7 −5 lib/Plack/Middleware/Auth/Form.pm
  3. +4 −2 t/unit.t
View
@@ -16,6 +16,8 @@ Revision history for Plack::Middleware::Auth::Form.
Some prerequisites added
{{$NEXT}}
+ More compliance with the PSGI spec:
Prefix for login form snippet is now 'Plack::Middleware::Auth::Form.LoginForm'
+ HTTP headers are now array reference (tokuhirom)
@@ -6,11 +6,13 @@ use parent qw/Plack::Middleware/;
use Plack::Util::Accessor qw( secure authenticator no_login_page after_logout );
use Plack::Request;
use Scalar::Util;
+use Carp ();
+
sub prepare_app {
my $self = shift;
- my $auth = $self->authenticator or die 'authenticator is not set';
+ my $auth = $self->authenticator or Carp::croak 'authenticator is not set';
if (Scalar::Util::blessed($auth) && $auth->can('authenticate')) {
$self->authenticator(sub { $auth->authenticate(@_[0,1]) }); # because Authen::Simple barfs on 3 params
} elsif (ref $auth ne 'CODE') {
@@ -46,7 +48,7 @@ sub _login {
my $secure_url = "https://$server" . $env->{PATH_INFO};
return [
301,
- { Location => $secure_url },
+ [ Location => $secure_url ],
[ "<html><body><a href=\"$secure_url\">Need a secure connection</a></body></html>" ]
];
}
@@ -73,7 +75,7 @@ sub _login {
URI->new( $redir_to )->path eq $env->{PATH_INFO};
return [
302,
- { Location => $redir_to },
+ [ Location => $redir_to ],
[ "<html><body><a href=\"$redir_to\">Back</a></body></html>" ]
];
}
@@ -91,7 +93,7 @@ sub _login {
else{
return [
200,
- { 'Content-Type' => 'text/html', },
+ [ 'Content-Type' => 'text/html', ],
[ "<html><body>$form\nAfter login: $env->{'psgix.session'}{redir_to}</body></html>" ]
];
}
@@ -125,7 +127,7 @@ sub _logout {
}
return [
303,
- { Location => $self->after_logout || '/' },
+ [ Location => $self->after_logout || '/' ],
[ "<html><body><a href=\"/\">Home</a></body></html>" ]
];
}
View
@@ -30,7 +30,8 @@ like( join( '', @{ $res->[2] } ), qr/form id="login_form"/, '/login with login f
is( $get_req->{'psgix.session'}{redir_to}, '/from_page' );
$res = $middleware->call( $post_req );
-is( $res->[1]{Location}, '/landing_page', 'Redirection after login' ) or warn Dumper($res);
+is( $res->[1][0], 'Location', 'Redirection after login' ) or warn Dumper($res);
+is( $res->[1][1], '/landing_page', 'Redirection after login' ) or warn Dumper($res);
is( $post_req->{'psgix.session'}{user_id}, 'joe', 'Username saved in the session' );
is( $post_req->{'psgix.session'}{redir_to}, undef, 'redir_to removed after usage' );
ok( !exists $post_req->{'psgix.session'}{remember} );
@@ -50,7 +51,8 @@ $post_req->{PATH_INFO} = '/logout';
$middleware = Plack::Middleware::Auth::Form->new( after_logout => '/after_logout' );
$res = $middleware->call( $post_req );
ok( !exists( $post_req->{'psgix.session'}{user_id} ), 'User logged out' );
-is( $res->[1]{Location}, '/after_logout', 'Redirection after logout' );
+is( $res->[1][0], 'Location', 'Redirection after logout' );
+is( $res->[1][1], '/after_logout', 'Redirection after logout' );
$middleware = Plack::Middleware::Auth::Form->new(
app => sub { [ 200, {}, [ 'aaa' . $_[0]->{'Plack::Middleware::Auth::Form.LoginForm'} ] ] },

0 comments on commit f6c7c15

Please sign in to comment.