line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::ServerTiming; |
2
|
5
|
|
|
5
|
|
12141
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
131
|
|
3
|
5
|
|
|
5
|
|
22
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
146
|
|
4
|
5
|
|
|
5
|
|
422
|
use parent qw/Plack::Middleware/; |
|
5
|
|
|
|
|
281
|
|
|
5
|
|
|
|
|
34
|
|
5
|
5
|
|
|
5
|
|
38654
|
use Plack::Util; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
1659
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = "0.04"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub call { |
10
|
4
|
|
|
4
|
1
|
77497
|
my ($self, $env) = @_; |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
|
|
48
|
my $res = $self->app->($env); |
13
|
|
|
|
|
|
|
$self->response_cb($res, sub { |
14
|
4
|
|
|
4
|
|
139
|
my $res = shift; |
15
|
|
|
|
|
|
|
|
16
|
4
|
100
|
|
|
|
22
|
return unless exists $env->{'psgix.server-timing'}; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
|
|
6
|
my @header; |
19
|
3
|
|
|
|
|
29
|
for my $metric (@{$env->{'psgix.server-timing'}}) { |
|
3
|
|
|
|
|
22
|
|
20
|
10
|
|
|
|
|
20
|
my $name = $metric->[0]; |
21
|
10
|
100
|
|
|
|
15
|
my %field = %{$metric->[1] || {}}; |
|
10
|
|
|
|
|
55
|
|
22
|
10
|
|
|
|
|
23
|
my @opt = map { "$_=" . _escape($field{$_}) } grep { defined $field{$_} } qw/dur desc/; |
|
10
|
|
|
|
|
31
|
|
|
20
|
|
|
|
|
56
|
|
23
|
10
|
|
|
|
|
39
|
push @header, join ';', $name, @opt; |
24
|
|
|
|
|
|
|
} |
25
|
3
|
|
|
|
|
25
|
Plack::Util::header_set($res->[1], 'Server-Timing', join(', ', @header)); |
26
|
4
|
|
|
|
|
233
|
}); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _escape { |
30
|
10
|
|
|
10
|
|
15
|
my $v = shift; |
31
|
10
|
100
|
66
|
|
|
79
|
if ($v =~ /[\x00-\x20()<>@,;:\\\"\/\[\]?={}\x7F-\xFF]/ || !length($v)) { |
32
|
3
|
|
|
|
|
9
|
$v =~ s/([\"\\])/\\$1/g; |
33
|
3
|
|
|
|
|
13
|
return qq{"$v"}; |
34
|
|
|
|
|
|
|
} else { |
35
|
7
|
|
|
|
|
33
|
return $v; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
__END__ |