X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FRequireSSL.pm;h=e73723714bf88252d770a58da7a1001be7c6658a;hb=61b3173919e7c140ba0160a57971d48e249c2f46;hp=edf613fedc02095241da46679cd919a4aa602c55;hpb=794abe2a200320318b087365f8141750a92f0647;p=catagits%2FCatalyst-Plugin-RequireSSL.git diff --git a/lib/Catalyst/Plugin/RequireSSL.pm b/lib/Catalyst/Plugin/RequireSSL.pm index edf613f..e737237 100644 --- a/lib/Catalyst/Plugin/RequireSSL.pm +++ b/lib/Catalyst/Plugin/RequireSSL.pm @@ -81,35 +81,18 @@ sub setup { 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 = $c->req->uri->clone; + $redir->scheme($type); + $redir->host_port($c->config->{require_ssl}->{$type}); - 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 ); - } - if ( $c->config->{require_ssl}->{no_cache} ) { delete $c->config->{require_ssl}->{$type}; }