examples/08-tls-introspection/app.pl

filter: Statementstmt 100% 40 / 40 Branchbran 68.7% 11 / 16 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 89.2% 58 / 65 CC 10 SCAR 16.5
CC
10
Cov
90%
app
8.1
drain_body
3.1
BEGIN
1.0
CRAP 5.2
« examples/04-websocket-echo/app.pl ↑ Summary blib/lib/PAGI/Server/ConnectionState.pm »
1 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use JSON::MaybeXS (); # for pretty output (optional)
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶async sub drain_body {
Subroutine drain_body: called CC=3 SCAR=11.2
7 8 my ($receive) = @_;
8  
9 8 while (1) {
10 8 my $event = await $receive->();
11 8 ▶ last if $event->{type} ne 'http.request';
Branch: 1 branch
BranchTrueFalseTotal
if $event->{"type"} ne "http.request" 0 8 8
12 8 ▶ last unless $event->{more};
Branch: 1 branch
BranchTrueFalseTotal
unless $event->{"more"} 8 0 8
13 }
14 4 }
15  
16 16 ▶async sub app {
Subroutine app: called CC=8 SCAR=20.9
17 16 my ($scope, $receive, $send) = @_;
18  
19 # Handle lifespan scope
20 16 ▶ if ($scope->{type} eq 'lifespan') {
Branch: 1 branch
BranchTrueFalseTotal
if ($scope->{"type"} eq "lifespan") 8 8 16
21 8 while (1) {
22 16 my $event = await $receive->();
23 16 ▶ if ($event->{type} eq 'lifespan.startup') {
Branch: 2 branches
BranchTrueFalseTotal
if ($event->{'type'} eq 'lifespan.startup') { } 8 8 16
elsif ($event->{'type'} eq 'lifespan.shutdown') { } 8 0 8
24 8 await $send->({ type => 'lifespan.startup.complete' });
25 }
26 elsif ($event->{type} eq 'lifespan.shutdown') {
27 8 await $send->({ type => 'lifespan.shutdown.complete' });
28 8 last;
29 }
30 }
31 8 return;
32 }
33  
34 8 ▶ die "Unsupported scope type: $scope->{type}" unless $scope->{type} eq 'http';
Branch: 1 branch
BranchTrueFalseTotal
unless $scope->{"type"} eq "http" 0 8 8
35 8 await drain_body($receive);
36  
37 8 my $tls = $scope->{extensions}{tls};
38 8 my $body;
39 8 ▶ if ($tls) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tls) { } 4 4 8
40 $body = "TLS info:\n" . JSON::MaybeXS->new->pretty(1)->encode({
41 tls_version => sprintf('0x%04x', $tls->{tls_version} // 0),
42 cipher_suite => defined $tls->{cipher_suite} ? sprintf('0x%04x', $tls->{cipher_suite}) : undef,
43 client_cert => $tls->{client_cert_name},
44 4 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
defined $tls->{'cipher_suite'} ? : 4 0 4
Condition50%1/2
$tls->{"tls_version"} // 0
l!l
40
MC/DC0%0/1
$tls->{"tls_version"} // 0
$tls->{"tls_version"}
Truth table50%1/2
A
A= $tls->{"tls_version"}
Aresult
11
00
45 }
46 else {
47 4 $body = "Connection is not using TLS";
48 }
49  
50 8 await $send->({
51 type => 'http.response.start',
52 status => 200,
53 headers => [ [ 'content-type', 'text/plain' ] ],
54 });
55  
56 8 await $send->({ type => 'http.response.body', body => $body, more => 0 });
57 4 }
58  
59 4 \&app;
« examples/04-websocket-echo/app.pl ↑ Summary blib/lib/PAGI/Server/ConnectionState.pm »