[Catalyst-commits] r10825 - in trunk/Catalyst-Plugin-RequireSSL: . lib/Catalyst/Plugin t

norbi at dev.catalyst.perl.org norbi at dev.catalyst.perl.org
Tue Jul 7 21:39:27 GMT 2009


Author: norbi
Date: 2009-07-07 21:39:27 +0000 (Tue, 07 Jul 2009)
New Revision: 10825

Modified:
   trunk/Catalyst-Plugin-RequireSSL/
   trunk/Catalyst-Plugin-RequireSSL/Changes
   trunk/Catalyst-Plugin-RequireSSL/lib/Catalyst/Plugin/RequireSSL.pm
   trunk/Catalyst-Plugin-RequireSSL/t/04ssl.t
Log:
 r10856 at vger:  mendel | 2009-07-07 23:39:01 +0200
 Cleaned up _redirect_uri() - replaced manual query param processing with manipulation of URI objects.



Property changes on: trunk/Catalyst-Plugin-RequireSSL
___________________________________________________________________
Name: svk:merge
   - cf8fe1c1-d5c0-41b4-84a9-31cb5e8e0cbe:/local/catalyst/Catalyst-Plugin-RequireSSL:10853
   + cf8fe1c1-d5c0-41b4-84a9-31cb5e8e0cbe:/local/catalyst/Catalyst-Plugin-RequireSSL:10856

Modified: trunk/Catalyst-Plugin-RequireSSL/Changes
===================================================================
--- trunk/Catalyst-Plugin-RequireSSL/Changes	2009-07-07 21:27:00 UTC (rev 10824)
+++ trunk/Catalyst-Plugin-RequireSSL/Changes	2009-07-07 21:39:27 UTC (rev 10825)
@@ -5,6 +5,7 @@
         - Fix POD coverage (t0m)
         - Added allow_ssl() (norbi)
         - Added detach_on_redirect config option (norbi)
+        - Cleaned up _redirect_uri() (norbi)
 
 0.06    2007-03-06 11:00:00
         - Added no_cache config option to support wildcard SSL certificates.

Modified: trunk/Catalyst-Plugin-RequireSSL/lib/Catalyst/Plugin/RequireSSL.pm
===================================================================
--- trunk/Catalyst-Plugin-RequireSSL/lib/Catalyst/Plugin/RequireSSL.pm	2009-07-07 21:27:00 UTC (rev 10824)
+++ trunk/Catalyst-Plugin-RequireSSL/lib/Catalyst/Plugin/RequireSSL.pm	2009-07-07 21:39:27 UTC (rev 10825)
@@ -81,35 +81,18 @@
 sub _redirect_uri {
     my ( $c, $type ) = @_;
 
-    # XXX: Cat needs a $c->req->host method...
-    # until then, strip off the leading protocol from base
     if ( !$c->config->{require_ssl}->{$type} ) {
-        my $host = $c->req->base;
-        $host =~ s/^http(s?):\/\///;
-        $c->config->{require_ssl}->{$type} = $host;
+        my $req_uri = $c->req->uri;
+        $c->config->{require_ssl}->{$type} =
+          join(':', $req_uri->host, $req_uri->_port);
     }
 
-    if ( $c->config->{require_ssl}->{$type} !~ /\/$/xms ) {
-        $c->config->{require_ssl}->{$type} .= '/';
-    }
+    $c->config->{require_ssl}->{$type} =~ s/\/+$//;
 
-    my $redir
-        = $type . '://' . $c->config->{require_ssl}->{$type} . $c->req->path;
-        
-    if ( scalar $c->req->param ) {
-        my @params;
-        foreach my $arg ( sort keys %{ $c->req->params } ) {
-            if ( ref $c->req->params->{$arg} ) {
-                my $list = $c->req->params->{$arg};
-                push @params, map { "$arg=" . $_  } sort @{$list};
-            }
-            else {
-                push @params, "$arg=" . $c->req->params->{$arg};
-            }
-        }
-        $redir .= '?' . join( '&', @params );
-    }  
-          
+    my $redir = $c->req->uri->clone;
+    $redir->scheme($type);
+    $redir->host_port($c->config->{require_ssl}->{$type});
+
     if ( $c->config->{require_ssl}->{no_cache} ) {        
         delete $c->config->{require_ssl}->{$type};
     }

Modified: trunk/Catalyst-Plugin-RequireSSL/t/04ssl.t
===================================================================
--- trunk/Catalyst-Plugin-RequireSSL/t/04ssl.t	2009-07-07 21:27:00 UTC (rev 10824)
+++ trunk/Catalyst-Plugin-RequireSSL/t/04ssl.t	2009-07-07 21:39:27 UTC (rev 10825)
@@ -17,7 +17,7 @@
 isnt( $res->content, 'Secured', 'no content displayed on secure page, ok' );
 
 # test redirection params
-ok( $res = request('http://localhost/ssl/secured?a=2&a=1&b=3&c=4'), 'request ok' );
+ok( $res = request('http://localhost/ssl/secured?a=1&a=2&b=3&c=4'), 'request ok' );
 is( $res->header('location'), 'https://localhost/ssl/secured?a=1&a=2&b=3&c=4', 'redirect with params ok' );
 
 # test that it does not redirect for actions where SSL mode is optional
@@ -47,7 +47,7 @@
     is( $res->header('location'), 'http://localhost/ssl/unsecured', 'redirect uri ok' );
     
     # test redirection params
-    ok( $res = request('https://localhost/ssl/unsecured?a=2&a=1&b=3&c=4'), 'request ok' );
+    ok( $res = request('https://localhost/ssl/unsecured?a=1&a=2&b=3&c=4'), 'request ok' );
     is( $res->header('location'), 'http://localhost/ssl/unsecured?a=1&a=2&b=3&c=4', 'redirect with params ok' );
 
     # test that it does not redirect for actions where SSL mode is optional




More information about the Catalyst-commits mailing list