Implemented $c->allow_ssl.
[catagits/Catalyst-Plugin-RequireSSL.git] / lib / Catalyst / Plugin / RequireSSL.pm
index bf665b5..6aafbc4 100644 (file)
@@ -6,7 +6,7 @@ use NEXT;
 
 our $VERSION = '0.07';
 
-__PACKAGE__->mk_accessors( qw/_require_ssl _ssl_strip_output/ );
+__PACKAGE__->mk_accessors( qw/_require_ssl _allow_ssl _ssl_strip_output/ );
 
 sub require_ssl {
     my $c = shift;
@@ -25,6 +25,12 @@ sub require_ssl {
     }
 }
 
+sub allow_ssl {
+    my $c = shift;
+
+    $c->_allow_ssl(1);
+}
+
 sub finalize {
     my $c = shift;
     
@@ -44,7 +50,7 @@ sub finalize {
         # we're already required to be in SSL for this request
         last REDIRECT if $c->_require_ssl;
         # or the user doesn't want us to redirect
-        last REDIRECT if $c->config->{require_ssl}->{remain_in_ssl};
+        last REDIRECT if $c->config->{require_ssl}->{remain_in_ssl} || $c->_allow_ssl;
         
         $c->res->redirect( $c->_redirect_uri('http') );
     }
@@ -187,6 +193,16 @@ Call require_ssl in any controller method you wish to be secured.
 The browser will be redirected to the same path on your SSL server.  POST
 requests are never redirected.
 
+=head2 allow_ssl
+
+Call allow_ssl in any controller method you wish to access both in SSL and
+non-SSL mode.
+
+    $c->allow_ssl;
+
+The browser will not be redirected, independently of whether the request was
+made to the SSL or non-SSL server.
+
 =head2 setup
 
 Disables this plugin if running under an engine which does not support SSL.