Net/Async/HTTP/Server/Protocol.pm

filter: Statementstmt 96.0% 49 / 51 Branchbran 81.2% 13 / 16 Conditioncond 50.0% 4 / 8 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 86.8% 79 / 91 CC 13 SCAR 13.7
CC
13
Cov
88%
on_read
7.4
_flush_requests
4.0
on_closed
3.0
CRAP 3.9
« Net/Async/HTTP/Server/PSGI.pm ↑ Summary Net/Async/HTTP/Server/Request.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2013-2023 -- leonerd@leonerd.org.uk
5  
6 package Net::Async::HTTP::Server::Protocol 0.15;
7  
8 13 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use base qw( IO::Async::Stream );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 13 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 13 my $CRLF = "\x0d\x0a";
18  
19 sub on_read
20 56 ▶{
Subroutine on_read: called CC=7 SCAR=20.0
Pod documented
21 56 my $self = shift;
22 56 my ( $buffref, $eof ) = @_;
23  
24 56 ▶ return 0 if $eof;
Branch: 1 branch
BranchTrueFalseTotal
if $eof 6 50 56
25  
26 50 ▶ return 0 unless $$buffref =~ s/^(.*?$CRLF$CRLF)//s;
Branch: 1 branch
BranchTrueFalseTotal
unless $$buffref =~ s/^(.*?$CRLF$CRLF)//su 24 26 50
27 26 my $header = $1;
28  
29 26 my $request = HTTP::Request->parse( $header );
30 26 ▶ unless( $request and defined $request->protocol and $request->protocol =~ m/^HTTP/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($request and defined $request->protocol and $request->protocol =~ /^HTTP/u) 0 26 26
Condition33%2/6
$request and defined $request->protocol and $request->protocol =~ /^HTTP/u
!ll&&!rl&&r
0026
$request and defined $request->protocol
!ll&&!rl&&r
0026
MC/DC0%0/3
$request and defined $request->protocol and $request->protocol =~ /^HTTP/u
$request defined $request->protocol $request->protocol =~ /^HTTP/u
Truth table25%1/4
A and B and C
A= $requestB= defined $request->protocolC= $request->protocol =~ /^HTTP/u
ABCresult
0XX0
10X0
1100
1111
31 0 $self->close_now;
32 0 return 0;
33 }
34  
35 26 ▶ my $request_body_len = $request->content_length || 0;
Condition100%2/2
$request->content_length || 0
l!l
323
MC/DC100%1/1
$request->content_length || 0
$request->content_length
Truth table100%2/2
A
A= $request->content_length
Aresult
11
00
36  
37 26 $self->debug_printf( "REQUEST %s %s", $request->method, $request->uri->path );
38  
39 27 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
40 27 my ( undef, $buffref, $eof ) = @_;
41  
42 27 ▶ return 0 unless length($$buffref) >= $request_body_len;
Branch: 1 branch
BranchTrueFalseTotal
unless length $$buffref >= $request_body_len 2 25 27
43  
44 25 $request->add_content( substr( $$buffref, 0, $request_body_len, "" ) );
45  
46 25 push @{ $self->{requests} }, my $req = $self->parent->make_request( $self, $request );
47 25 weaken( $self->{requests}[-1] );
48  
49 25 $self->parent->_received_request( $req );
50  
51 25 return undef;
52 26 };
53 }
54  
55 sub on_closed
56 8 ▶{
Subroutine on_closed: called CC=3 SCAR=11.1
Pod documented
57 8 my $self = shift;
58  
59 8 ▶ $_ and $_->_close for @{ $self->{requests} };
Branch: 1 branch
BranchTrueFalseTotal
$_ and $_->_close 1 0 1
60 8 undef @{ $self->{requests} };
61 }
62  
63 sub _flush_requests
64 61 ▶{
Subroutine _flush_requests: called CC=4 SCAR=13.9
65 61 my $self = shift;
66  
67 61 my $queue = $self->{requests};
68 61 ▶ while( @$queue ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$queue) 62 20 82
69 62 my $req = $queue->[0];
70 62 ▶ $req or shift @$queue, next;
Branch: 1 branch
BranchTrueFalseTotal
$req or shift @$queue, next 62 0 62
71  
72 62 my $is_done = $req->_write_to_stream( $self );
73  
74 62 ▶ $is_done ? shift @$queue : return;
Branch: 1 branch
BranchTrueFalseTotal
$is_done ? : 21 41 62
75 }
76 }
77  
78 13 0x55AA;
« Net/Async/HTTP/Server/PSGI.pm ↑ Summary Net/Async/HTTP/Server/Request.pm »