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};
}