line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
78909
|
use 5.010; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
56
|
|
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
81
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Plack::Middleware::RedirectSSL; |
6
|
|
|
|
|
|
|
$Plack::Middleware::RedirectSSL::VERSION = '1.104'; |
7
|
|
|
|
|
|
|
# ABSTRACT: force all requests to use in-/secure connections |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use parent 'Plack::Middleware'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
79
|
use Plack::Util (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
12
|
1
|
|
|
1
|
|
6
|
use Plack::Util::Accessor qw( ssl hsts ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
13
|
1
|
|
|
1
|
|
805
|
use Plack::Request (); |
|
1
|
|
|
|
|
48788
|
|
|
1
|
|
|
|
|
348
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# seconds minutes hours days weeks |
16
|
|
|
|
|
|
|
sub DEFAULT_STS_MAXAGE () { 60 * 60 * 24 * 7 * 26 } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub call { |
19
|
19
|
|
|
19
|
1
|
93790
|
my $self = shift; |
20
|
19
|
|
|
|
|
27
|
my $env = shift; |
21
|
|
|
|
|
|
|
|
22
|
19
|
100
|
100
|
|
|
54
|
my $do_ssl = ( $self->ssl // 1 ) ? 1 : 0; |
23
|
19
|
100
|
|
|
|
267
|
my $is_ssl = ( 'https' eq $env->{'psgi.url_scheme'} ) ? 1 : 0; |
24
|
|
|
|
|
|
|
|
25
|
19
|
100
|
100
|
|
|
101
|
if ( $is_ssl xor $do_ssl ) { |
26
|
9
|
|
|
|
|
17
|
my $m = $env->{'REQUEST_METHOD'}; |
27
|
9
|
100
|
100
|
|
|
49
|
return [ 400, [qw( Content-Type text/plain )], [ 'Bad Request' ] ] |
28
|
|
|
|
|
|
|
if 'GET' ne $m and 'HEAD' ne $m; |
29
|
7
|
|
|
|
|
49
|
my $uri = Plack::Request->new( $env )->uri; |
30
|
7
|
100
|
|
|
|
1658
|
$uri->scheme( $do_ssl ? 'https' : 'http' ); |
31
|
7
|
|
|
|
|
1468
|
return [ 301, [ Location => $uri ], [] ]; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
10
|
|
|
|
|
31
|
my $res = $self->app->( $env ); |
35
|
|
|
|
|
|
|
|
36
|
10
|
100
|
100
|
|
|
173
|
if ( $is_ssl and $self->hsts // 1 ) { |
|
|
|
66
|
|
|
|
|
37
|
6
|
|
100
|
|
|
43
|
my $max_age = 0 + ( $self->hsts // DEFAULT_STS_MAXAGE ); |
38
|
|
|
|
|
|
|
$res = Plack::Util::response_cb( $res, sub { |
39
|
6
|
|
|
6
|
|
72
|
my $res = shift; |
40
|
6
|
|
|
|
|
31
|
Plack::Util::header_set( $res->[1], 'Strict-Transport-Security', "max-age=$max_age" ); |
41
|
6
|
|
|
|
|
66
|
} ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
10
|
|
|
|
|
280
|
return $res; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__END__ |