HTTP2/Frame/Headers.pm

filter: Statementstmt 79.2% 42 / 53 Branchbran 66.6% 12 / 18 Conditioncond 66.6% 8 / 12 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 71.1% 69 / 97 CC 14 SCAR 20.0
CC
14
Cov
75%
decode
10.1
encode
8.0
BEGIN
1.0
CRAP 7.4
« HTTP2/Server.pm ↑ Summary HTTP2/Client.pm »
1 package Protocol::HTTP2::Frame::Headers;
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 :states :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 # 6.2 HEADERS
8 76 ▶sub decode {
Subroutine decode: called CC=8 SCAR=23.1
Pod undocumented
9 76 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
10 76 my ( $pad, $offset, $weight, $exclusive, $stream_dep ) = ( 0, 0 );
11 76 my $frame_ref = $con->decode_context->{frame};
12  
13 # Protocol errors
14 76 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($frame_ref->{"stream"} == 0) 0 76 76
15 # HEADERS frames MUST be associated with a stream
16 $frame_ref->{stream} == 0
17 )
18 {
19 0 $con->error(PROTOCOL_ERROR);
20 0 return undef;
21 }
22  
23 76 ▶ if ( $frame_ref->{flags} & PADDED ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frame_ref->{"flags"} & 8) 0 76 76
24 0 $pad = unpack( 'C', substr( $$buf_ref, $buf_offset, 1 ) );
25 0 $offset += 1;
26 }
27  
28 76 ▶ if ( $frame_ref->{flags} & PRIORITY_FLAG ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frame_ref->{"flags"} & 32) 1 75 76
29 1 ( $stream_dep, $weight ) =
30 unpack( 'NC', substr( $$buf_ref, $buf_offset + $offset, 5 ) );
31 1 $exclusive = $stream_dep >> 31;
32 1 $stream_dep &= 0x7FFF_FFFF;
33 1 $weight++;
34  
35 1 $con->stream_weight( $frame_ref->{stream}, $weight );
36 1 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($con->stream_reprio($frame_ref->{"stream"}, $exclusive, $stream_dep)) 0 1 1
37 $con->stream_reprio(
38 $frame_ref->{stream}, $exclusive, $stream_dep
39 )
40 )
41 {
42 0 tracer->error("Malformed HEADERS frame priority");
43 0 $con->error(PROTOCOL_ERROR);
44 0 return undef;
45 }
46  
47 1 $offset += 5;
48 }
49  
50 # Not enough space for header block
51 76 my $hblock_size = $length - $offset - $pad;
52 76 ▶ if ( $hblock_size < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hblock_size < 0) 0 76 76
53 0 $con->error(PROTOCOL_ERROR);
54 0 return undef;
55 }
56  
57 $con->stream_header_block( $frame_ref->{stream},
58 76 substr( $$buf_ref, $buf_offset + $offset, $hblock_size ) );
59  
60 # Stream header block complete
61 $con->stream_headers_done( $frame_ref->{stream} )
62 or return undef
63 76 ▶ if $frame_ref->{flags} & END_HEADERS;
Branch: 1 branch
BranchTrueFalseTotal
if $frame_ref->{"flags"} & 4 75 1 76
Condition80%4/5
$frame_ref->{'flags'} & 4 && ($con->stream_headers_done($frame_ref->{'stream'}) || (return undef))
!ll&&!rl&&r
1750
$con->stream_headers_done($frame_ref->{"stream"}) or return undef
l!l
732
MC/DC0%0/2
$frame_ref->{'flags'} & 4 && ($con->stream_headers_done($frame_ref->{'stream'}) || (return undef))
$frame_ref->{'flags'} & 4 $con->stream_headers_done($frame_ref->{"stream"})
Truth table66%2/3
A && B
A= $frame_ref->{'flags'} & 4B= $con->stream_headers_done($frame_ref->{"stream"})
ABresult
0X0
100
111
64  
65 74 return $length;
66 }
67  
68 78 ▶sub encode {
Subroutine encode: called CC=7 SCAR=20.7
Pod undocumented
69 78 my ( $con, $flags_ref, $stream, $data_ref ) = @_;
70 78 my $res = '';
71  
72 78 ▶ if ( exists $data_ref->{padding} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data_ref->{"padding"}) 0 78 78
73 0 $$flags_ref |= PADDED;
74 0 $res .= pack 'C', $data_ref->{padding};
75 }
76  
77 78 ▶ if ( exists $data_ref->{stream_dep} || exists $data_ref->{weight} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data_ref->{"stream_dep"} or exists $data_ref->{"weight"}) 1 77 78
Condition66%2/3
exists $data_ref->{"stream_dep"} or exists $data_ref->{"weight"}
l!l&&r!l&&!r
1077
MC/DC50%1/2
exists $data_ref->{"stream_dep"} or exists $data_ref->{"weight"}
exists $data_ref->{"stream_dep"} exists $data_ref->{"weight"}
Truth table66%2/3
A or B
A= exists $data_ref->{"stream_dep"}B= exists $data_ref->{"weight"}
ABresult
1X1
011
000
78 1 $$flags_ref |= PRIORITY_FLAG;
79 1 ▶ my $weight = ( $data_ref->{weight} || DEFAULT_WEIGHT ) - 1;
Condition50%1/2
$data_ref->{'weight'} || 16
l!l
10
MC/DC0%0/1
$data_ref->{'weight'} || 16
$data_ref->{'weight'}
Truth table50%1/2
A
A= $data_ref->{'weight'}
Aresult
11
00
80 1 ▶ my $stream_dep = $data_ref->{stream_dep} || 0;
Condition50%1/2
$data_ref->{'stream_dep'} || 0
l!l
01
MC/DC0%0/1
$data_ref->{'stream_dep'} || 0
$data_ref->{'stream_dep'}
Truth table50%1/2
A
A= $data_ref->{'stream_dep'}
Aresult
11
00
81 1 ▶ $stream_dep |= ( 1 << 31 ) if $data_ref->{exclusive};
Branch: 1 branch
BranchTrueFalseTotal
if $data_ref->{"exclusive"} 0 1 1
82 1 $res .= pack 'NC', $stream_dep, $weight;
83 }
84  
85 78 return $res . ${ $data_ref->{hblock} };
86 }
87  
88 13 1;
« HTTP2/Server.pm ↑ Summary HTTP2/Client.pm »