HTTP2/Frame/Data.pm

filter: Statementstmt 73.9% 34 / 46 Branchbran 66.6% 12 / 18 Conditioncond 50.0% 6 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 63.7% 58 / 91 CC 14 SCAR 29.6
CC
14
Cov
68%
decode
25.9
BEGIN
1.0
BEGIN
1.0
CRAP 19.4
« HTTP2/Stream.pm ↑ Summary HTTP2/Frame/Window_update.pm »
1 package Protocol::HTTP2::Frame::Data;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use Protocol::HTTP2::Constants qw(:flags :errors :settings :limits);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Protocol::HTTP2::Trace qw(tracer);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 49 ▶sub decode {
Subroutine decode: called CC=14 SCAR=32.6
Pod undocumented
8 49 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
9 49 my ( $pad, $offset ) = ( 0, 0 );
10 49 my $frame_ref = $con->decode_context->{frame};
11  
12 # Protocol errors
13 49 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($frame_ref->{"stream"} == 0) 0 49 49
14 # DATA frames MUST be associated with a stream
15 $frame_ref->{stream} == 0
16 )
17 {
18 0 $con->error(PROTOCOL_ERROR);
19 0 return undef;
20 }
21  
22 49 ▶ if ( $frame_ref->{flags} & PADDED ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frame_ref->{"flags"} & 8) 0 49 49
23 0 $pad = unpack( 'C', substr( $$buf_ref, $buf_offset ) );
24 0 $offset += 1;
25 }
26  
27 49 my $dblock_size = $length - $offset - $pad;
28 49 ▶ if ( $dblock_size < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dblock_size < 0) 0 49 49
29 0 tracer->error("Not enough space for data block\n");
30 0 $con->error(PROTOCOL_ERROR);
31 0 return undef;
32 }
33  
34 49 my $fcw = $con->fcw_recv( -$length );
35 49 my $stream_fcw = $con->stream_fcw_recv( $frame_ref->{stream}, -$length );
36 49 ▶ if ( $fcw < 0 || $stream_fcw < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fcw < 0 or $stream_fcw < 0) 0 49 49
Condition33%1/3
$fcw < 0 or $stream_fcw < 0
l!l&&r!l&&!r
0049
MC/DC0%0/2
$fcw < 0 or $stream_fcw < 0
$fcw < 0 $stream_fcw < 0
Truth table33%1/3
A or B
A= $fcw < 0B= $stream_fcw < 0
ABresult
1X1
011
000
37 0 tracer->warning(
38 "received data overflow flow control window: $fcw|$stream_fcw\n");
39 0 $con->stream_error( $frame_ref->{stream}, FLOW_CONTROL_ERROR );
40 0 return $length;
41 }
42 49 ▶ $con->fcw_update() if $fcw < $con->dec_setting(SETTINGS_MAX_FRAME_SIZE);
Branch: 1 branch
BranchTrueFalseTotal
if $fcw < $con->dec_setting(5) 1 48 49
43 $con->stream_fcw_update( $frame_ref->{stream} )
44 if $stream_fcw < $con->dec_setting(SETTINGS_MAX_FRAME_SIZE)
45 49 ▶ && !( $frame_ref->{flags} & END_STREAM );
Branch: 1 branch
BranchTrueFalseTotal
if $stream_fcw < $con->dec_setting(5) and not $frame_ref->{"flags"} & 1 0 49 49
Condition33%1/3
$stream_fcw < $con->dec_setting(5) and not $frame_ref->{"flags"} & 1
!ll&&!rl&&r
4900
MC/DC0%0/2
$stream_fcw < $con->dec_setting(5) and not $frame_ref->{"flags"} & 1
$stream_fcw < $con->dec_setting(5) not $frame_ref->{"flags"} & 1
Truth table33%1/3
A and not(B)
A= $stream_fcw < $con->dec_setting(5)B= not $frame_ref->{"flags"} & 1
ABresult
0X0
100
111
46  
47 49 ▶ return $length unless $dblock_size;
Branch: 1 branch
BranchTrueFalseTotal
unless $dblock_size 29 20 49
48  
49 20 my $data = substr $$buf_ref, $buf_offset + $offset, $dblock_size;
50  
51 # Update stream data container
52 20 $con->stream_data( $frame_ref->{stream}, $data );
53  
54 # Check length of data matched content-length in header
55 20 ▶ if ( $frame_ref->{flags} & END_STREAM ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frame_ref->{"flags"} & 1) 5 15 20
56 5 my $slen = $con->stream_length( $frame_ref->{stream} );
57 5 ▶ if ( defined $slen && defined $con->stream_data( $frame_ref->{stream} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $slen and defined $con->stream_data($frame_ref->{"stream"}) and $slen != length $con->stream_data($frame_ref->{"stream"})) 0 5 5
Condition66%4/6
defined $slen and defined $con->stream_data($frame_ref->{"stream"}) and $slen != length $con->stream_data($frame_ref->{"stream"})
!ll&&!rl&&r
230
defined $slen and defined $con->stream_data($frame_ref->{"stream"})
!ll&&!rl&&r
203
MC/DC0%0/3
defined $slen and defined $con->stream_data($frame_ref->{"stream"}) and $slen != length $con->stream_data($frame_ref->{"stream"})
defined $slen defined $con->stream_data($frame_ref->{"stream"}) $slen != length $con->stream_data($frame_ref->{"stream"})
Truth table50%2/4
A and B and C
A= defined $slenB= defined $con->stream_data($frame_ref->{"stream"})C= $slen != length $con->stream_data($frame_ref->{"stream"})
ABCresult
0XX0
10X0
1100
1111
58 && $slen != length $con->stream_data( $frame_ref->{stream} ) )
59 {
60 0 tracer->warning(
61 "content-length header don't match data frames size\n");
62 0 $con->stream_error( $frame_ref->{stream}, PROTOCOL_ERROR );
63 }
64 }
65  
66 20 return $length;
67 }
68  
69 48 ▶sub encode {
Subroutine encode: called CC=1 SCAR=0.0
Pod undocumented
70 48 my ( $con, $flags_ref, $stream_id, $data_ref ) = @_;
71  
72 48 return $$data_ref;
73 }
74  
75 13 1;
« HTTP2/Stream.pm ↑ Summary HTTP2/Frame/Window_update.pm »