File Coverage

blib/lib/Mojolicious/Plugin/SecureOnly.pm
Criterion Covered Total %
statement 12 12 100.0
branch 2 4 50.0
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 18 20 90.0


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::SecureOnly;
2 1     1   744 use Mojo::Base 'Mojolicious::Plugin';
  1         3  
  1         7  
3              
4             our $VERSION = '0.01';
5              
6             sub register {
7 1     1 1 40 my ($self, $app, $config) = @_;
8              
9             $app->hook(before_dispatch => sub {
10 1     1   9347 my $c = shift;
11 1 50       7 return if $c->req->is_secure;
12              
13 1         43 my $url = $c->req->url->to_abs;
14 1         224 $url->scheme('https');
15 1 50       8 $url->port($config->{secureport}) if $config->{secureport};
16 1         4 $c->app->log->debug("SecureOnly: $url");
17 1         221 $c->redirect_to($url);
18 1         18 });
19             }
20              
21             1;
22             __END__