line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# TODO: |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Redo fingerprinting |
4
|
|
|
|
|
|
|
package Cog::Runner; |
5
|
2
|
|
|
2
|
|
1431
|
use Mo; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
extends 'Cog::Base'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1030
|
use Plack::Builder; |
|
2
|
|
|
|
|
16711
|
|
|
2
|
|
|
|
|
173
|
|
9
|
2
|
|
|
2
|
|
1053
|
use Plack::Runner; |
|
2
|
|
|
|
|
8682
|
|
|
2
|
|
|
|
|
21
|
|
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
0
|
0
|
|
sub fingerprinted { $_[0]->{PATH_INFO} =~ /[0-9a-f]{32}/ } |
12
|
2
|
|
|
2
|
|
133
|
use constant MAX_DATE => 'Sun, 17-Jan-2038 19:14:07 GMT'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
917
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub app { |
15
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
16
|
|
|
|
|
|
|
return builder { |
17
|
|
|
|
|
|
|
# Serve cached stuff... |
18
|
0
|
0
|
|
0
|
|
|
enable 'Cache' => ( |
19
|
|
|
|
|
|
|
match_url => $self->config->cache_urls, |
20
|
|
|
|
|
|
|
cache_dir => 'cache', |
21
|
|
|
|
|
|
|
) if $self->config->cache_urls; |
22
|
|
|
|
|
|
|
# If this is a proxy url, just serve that. |
23
|
0
|
0
|
|
|
|
|
enable 'ProxyMap' => ( |
24
|
|
|
|
|
|
|
proxymap => $self->config->proxymap, |
25
|
|
|
|
|
|
|
) if $self->config->proxymap; |
26
|
|
|
|
|
|
|
# Fingerprinted files live forever |
27
|
0
|
|
|
|
|
|
enable_if sub { fingerprinted(@_) }, |
28
|
0
|
|
|
|
|
|
'Header', set => ['Expires' => MAX_DATE]; |
29
|
|
|
|
|
|
|
# All other files get ETagged |
30
|
0
|
|
|
|
|
|
enable_if sub { ! fingerprinted(@_) }, |
31
|
0
|
|
|
|
|
|
'Header', set => ['Cache-Control' => 'no-cache']; |
32
|
0
|
|
|
|
|
|
enable 'ConditionalGET'; |
33
|
0
|
|
|
|
|
|
enable 'ETag', file_etag => [qw/inode mtime size/]; |
34
|
|
|
|
|
|
|
# Serve static files from disk |
35
|
0
|
0
|
|
|
|
|
if (my $rewrites = $self->webapp->rewrite) { |
36
|
|
|
|
|
|
|
enable 'Rewrite', rules => sub { |
37
|
0
|
|
|
|
|
|
for my $rewrite (@$rewrites) { |
38
|
0
|
0
|
|
|
|
|
s!$rewrite->[0]!$rewrite->[1]! and last; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
return; |
41
|
0
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
enable 'Static', |
44
|
|
|
|
|
|
|
path => qr{^/(all-.*\.(css|js)|image/)}, |
45
|
|
|
|
|
|
|
root => $self->config->app->webapp_root; |
46
|
|
|
|
|
|
|
# Everything else is from the web app. |
47
|
0
|
|
|
|
|
|
$self->webapp->web_app; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub run { |
52
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
53
|
0
|
|
|
|
|
|
my @args = $self->get_args(@_); |
54
|
0
|
|
|
|
|
|
my $runner = Plack::Runner->new; |
55
|
0
|
|
|
|
|
|
$runner->parse_options(@args); |
56
|
0
|
|
|
|
|
|
$runner->run($self->app); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# TODO integrate these into config |
60
|
|
|
|
|
|
|
sub get_args { |
61
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
62
|
0
|
|
|
|
|
|
my %args = @_; |
63
|
0
|
0
|
|
|
|
|
if ($ENV{COG_HOST}) { |
64
|
0
|
|
|
|
|
|
delete @args{qw(--host -h)}; |
65
|
0
|
|
|
|
|
|
$args{'--host'} = $ENV{COG_HOST}; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
0
|
|
|
|
|
if ($ENV{COG_PORT}) { |
68
|
0
|
|
|
|
|
|
delete @args{qw(--port -p)}; |
69
|
0
|
|
|
|
|
|
$args{'--port'} = $ENV{COG_PORT}; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
0
|
|
|
|
|
if ($ENV{COG_SERVER}) { |
72
|
0
|
|
|
|
|
|
delete @args{qw(--server -s)}; |
73
|
0
|
|
|
|
|
|
$args{'--server'} = $ENV{COG_SERVER}; |
74
|
|
|
|
|
|
|
} |
75
|
0
|
0
|
|
|
|
|
if ($ENV{COG_DAEMONIZE}) { |
76
|
0
|
|
|
|
|
|
delete @args{qw(--daemonize -D)}; |
77
|
0
|
|
|
|
|
|
$args{'--daemonize'} = $ENV{COG_DAEMONIZE}; |
78
|
0
|
|
|
|
|
|
$args{'--pid'} = 'cog.pid'; |
79
|
|
|
|
|
|
|
} |
80
|
0
|
0
|
|
|
|
|
if ($ENV{COG_LOG}) { |
81
|
0
|
|
|
|
|
|
delete @args{qw(--access-log)}; |
82
|
0
|
|
|
|
|
|
$args{'--access-log'} = $ENV{COG_LOG}; |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
return %args; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |