| 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
| |||||||||||||||||||||
| 12 | 8 | ▶ | last unless $event->{more}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 21 | 8 | while (1) { | |||||||||||||||||||
| 22 | 16 | my $event = await $receive->(); | |||||||||||||||||||
| 23 | 16 | ▶ | if ($event->{type} eq 'lifespan.startup') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
Condition50%1/2
$tls->{"tls_version"} // 0
MC/DC0%0/1
$tls->{"tls_version"} // 0
$tls->{"tls_version"}
Truth table50%1/2
A
A= $tls->{"tls_version"}
| |||||||||||||||||||||
| 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; | |||||||||||||||||||