HTTP2/Connection.pm

filter: Statementstmt 78.0% 160 / 205 Branchbran 67.5% 81 / 120 Conditioncond 60.0% 63 / 105 MC/DCmcdc 33.3% 19 / 57 Subroutinesub 92.3% 36 / 39 Podpod 0.0% 0 / 29 totaltotal 64.6% 359 / 555 CC 102 SCAR 51.5
CC
102
Cov
71%
state_machine
396.0
send_pp_headers
20.0
fcw_initial_change
12.0
CRAP 172.5
↑ Summary HTTP2/HeaderCompression.pm »
1 package Protocol::HTTP2::Connection;
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 use Protocol::HTTP2::Constants
5 13 ▶ qw(const_name :frame_types :errors :settings :flags :states
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 :limits :endpoints);
7 13 ▶use Protocol::HTTP2::HeaderCompression qw(headers_encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Protocol::HTTP2::Frame;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Protocol::HTTP2::Stream;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use Protocol::HTTP2::Upgrade;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use Protocol::HTTP2::Trace qw(tracer);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # Mixin
14 13 our @ISA =
15 qw(Protocol::HTTP2::Frame Protocol::HTTP2::Stream Protocol::HTTP2::Upgrade);
16  
17 # Default settings
18 13 my %default_settings = (
19 &SETTINGS_HEADER_TABLE_SIZE => DEFAULT_HEADER_TABLE_SIZE,
20 &SETTINGS_ENABLE_PUSH => DEFAULT_ENABLE_PUSH,
21 &SETTINGS_MAX_CONCURRENT_STREAMS => DEFAULT_MAX_CONCURRENT_STREAMS,
22 &SETTINGS_INITIAL_WINDOW_SIZE => DEFAULT_INITIAL_WINDOW_SIZE,
23 &SETTINGS_MAX_FRAME_SIZE => DEFAULT_MAX_FRAME_SIZE,
24 &SETTINGS_MAX_HEADER_LIST_SIZE => DEFAULT_MAX_HEADER_LIST_SIZE,
25 );
26  
27 48 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod undocumented
28 48 my ( $class, $type, %opts ) = @_;
29 48 ▶ my $self = bless {
Branch: 1 branch
BranchTrueFalseTotal
$type == 1 ? : 24 24 48
30 type => $type,
31  
32 streams => {},
33 closed_streams => [],
34 max_closed_streams => PH2_MAX_CLOSED_STREAMS,
35  
36 last_stream => $type == CLIENT ? 1 : 2,
37 last_peer_stream => 0,
38 active_peer_streams => 0,
39  
40 encode_ctx => {
41  
42 # HPACK. Header Table
43 header_table => [],
44  
45 # HPACK. Header Table size
46 ht_size => 0,
47 max_ht_size => DEFAULT_HEADER_TABLE_SIZE,
48  
49 settings => {%default_settings},
50  
51 },
52  
53 decode_ctx => {
54  
55 # HPACK. Header Table
56 header_table => [],
57  
58 # HPACK. Header Table size
59 ht_size => 0,
60 max_ht_size => DEFAULT_HEADER_TABLE_SIZE,
61  
62 # HPACK. Emitted headers
63 emitted_headers => [],
64  
65 # last frame
66 frame => {},
67  
68 settings => {%default_settings},
69 },
70  
71 # Current error
72 error => 0,
73  
74 # Output frames queue
75 queue => [],
76  
77 # Connection must be shutdown
78 shutdown => 0,
79  
80 # issued GOAWAY: no new streams on this connection
81 goaway => 0,
82  
83 # get preface
84 preface => 0,
85  
86 # perform upgrade
87 upgrade => 0,
88  
89 # flow control
90 fcw_send => DEFAULT_INITIAL_WINDOW_SIZE,
91 fcw_recv => DEFAULT_INITIAL_WINDOW_SIZE,
92  
93 # stream where expected CONTINUATION frames
94 pending_stream => undef,
95  
96 }, $class;
97  
98 48 for (qw(on_change_state on_new_peer_stream on_error upgrade max_closed_streams)) {
99 240 ▶ $self->{$_} = $opts{$_} if exists $opts{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{$_} 25 215 240
100 }
101  
102 48 ▶ if ( exists $opts{settings} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"settings"}) 20 28 48
103 20 for ( keys %{ $opts{settings} } ) {
104 21 $self->{decode_ctx}->{settings}->{$_} = $opts{settings}{$_};
105 }
106 }
107  
108 # Sync decode context max_ht_size
109 $self->{decode_ctx}->{max_ht_size} =
110 48 $self->{decode_ctx}->{settings}->{&SETTINGS_HEADER_TABLE_SIZE};
111  
112 48 $self;
113 }
114  
115 656 ▶sub decode_context {
Subroutine decode_context: called CC=1 SCAR=0.0
Pod undocumented
116 656 shift->{decode_ctx};
117 }
118  
119 77 ▶sub encode_context {
Subroutine encode_context: called CC=1 SCAR=0.0
Pod undocumented
120 77 shift->{encode_ctx};
121 }
122  
123 214 ▶sub pending_stream {
Subroutine pending_stream: called CC=1 SCAR=0.0
Pod undocumented
124 214 shift->{pending_stream};
125 }
126  
127 415 ▶sub dequeue {
Subroutine dequeue: called CC=1 SCAR=0.0
Pod undocumented
128 415 my $self = shift;
129 415 shift @{ $self->{queue} };
130 }
131  
132 21 ▶sub enqueue_raw {
Subroutine enqueue_raw: called CC=1 SCAR=0.0
Pod undocumented
133 21 my $self = shift;
134 21 push @{ $self->{queue} }, @_;
135 }
136  
137 217 ▶sub enqueue {
Subroutine enqueue: called CC=2 SCAR=6.9
Pod undocumented
138 217 my $self = shift;
139 217 ▶ while ( my ( $type, $flags, $stream_id, $data_ref ) = splice( @_, 0, 4 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 4)) 219 217 436
140 219 push @{ $self->{queue} },
141 $self->frame_encode( $type, $flags, $stream_id, $data_ref );
142 219 $self->state_machine( 'send', $type, $flags, $stream_id );
143 }
144 }
145  
146 2 ▶sub enqueue_first {
Subroutine enqueue_first: called CC=5 SCAR=16.1
Pod undocumented
147 2 my $self = shift;
148 2 my $i = 0;
149 2 for ( 0 .. $#{ $self->{queue} } ) {
150 my $type =
151 2 ( $self->frame_header_decode( \$self->{queue}->[$_], 0 ) )[1];
152 2 ▶ last if $type != CONTINUATION && $type != PING;
Branch: 1 branch
BranchTrueFalseTotal
if $type != 9 and $type != 6 1 1 2
Condition66%2/3
$type != 9 and $type != 6
!ll&&!rl&&r
101
MC/DC50%1/2
$type != 9 and $type != 6
$type != 9 $type != 6
Truth table66%2/3
A and B
A= $type != 9B= $type != 6
ABresult
0X0
100
111
153 1 $i++;
154 }
155 2 ▶ while ( my ( $type, $flags, $stream_id, $data_ref ) = splice( @_, 0, 4 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 4)) 2 2 4
156 2 splice @{ $self->{queue} }, $i++, 0,
157 $self->frame_encode( $type, $flags, $stream_id, $data_ref );
158 2 $self->state_machine( 'send', $type, $flags, $stream_id );
159 }
160 }
161  
162 12 ▶sub finish {
Subroutine finish: called CC=2 SCAR=7.1
Pod undocumented
163 12 my $self = shift;
164 $self->enqueue( GOAWAY, 0, 0,
165 12 ▶ [ $self->{last_peer_stream}, $self->{error} ] )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->shutdown 12 0 12
166 unless $self->shutdown;
167 12 $self->shutdown(1);
168 }
169  
170 32 ▶sub shutdown {
Subroutine shutdown: called CC=2 SCAR=6.9
Pod undocumented
171 32 my $self = shift;
172 32 ▶ $self->{shutdown} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 13 19 32
173 32 $self->{shutdown};
174 }
175  
176 110 ▶sub goaway {
Subroutine goaway: called CC=2 SCAR=6.9
Pod undocumented
177 110 my $self = shift;
178 110 ▶ $self->{goaway} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 21 89 110
179 110 $self->{goaway};
180 }
181  
182 446 ▶sub preface {
Subroutine preface: called CC=2 SCAR=6.9
Pod undocumented
183 446 my $self = shift;
184 446 ▶ $self->{preface} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 39 407 446
185 446 $self->{preface};
186 }
187  
188 543 ▶sub upgrade {
Subroutine upgrade: called CC=2 SCAR=7.1
Pod undocumented
189 543 my $self = shift;
190 543 ▶ $self->{upgrade} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 543 543
191 543 $self->{upgrade};
192 }
193  
194 433 ▶sub state_machine {
Subroutine state_machine: called CC=60 SCAR=59.8
Pod undocumented
195 433 my ( $self, $act, $type, $flags, $stream_id ) = @_;
196  
197 return
198 433 ▶ if $stream_id == 0
Branch: 1 branch
BranchTrueFalseTotal
if $stream_id == 0 or $type == 4 or $type == 7 or $self->upgrade or not $self->preface 173 260 433
Condition66%8/12
$stream_id == 0 or $type == 4 or $type == 7 or $self->upgrade or not $self->preface
l!l&&r!l&&!r
1730260
$stream_id == 0 or $type == 4 or $type == 7 or $self->upgrade
l!l&&r!l&&!r
1730260
$stream_id == 0 or $type == 4 or $type == 7
l!l&&r!l&&!r
1730260
$stream_id == 0 or $type == 4
l!l&&r!l&&!r
1730260
MC/DC20%1/5
$stream_id == 0 or $type == 4 or $type == 7 or $self->upgrade or not $self->preface
$stream_id == 0 $type == 4 $type == 7 $self->upgrade not $self->preface
Truth table33%2/6
A or B or C or D or not(E)
A= $stream_id == 0B= $type == 4C= $type == 7D= $self->upgradeE= not $self->preface
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
199 || $type == SETTINGS
200 || $type == GOAWAY
201 || $self->upgrade
202 || !$self->preface;
203  
204 260 my $promised_sid = $self->stream_promised_sid($stream_id);
205  
206 260 ▶ my $prev_state = $self->{streams}->{ $promised_sid || $stream_id }->{state};
Condition33%1/3
$promised_sid || $stream_id
l!l&&r!l&&!r
02600
MC/DC0%0/2
$promised_sid || $stream_id
$promised_sid $stream_id
Truth table33%1/3
A || B
A= $promised_sidB= $stream_id
ABresult
1X1
011
000
207  
208 # REFUSED_STREAM error
209 260 ▶ return if !defined $prev_state && $type == RST_STREAM && $act eq 'send';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $prev_state and $type == 3 and $act eq "send" 0 260 260
Condition33%2/6
not defined $prev_state and $type == 3 and $act eq "send"
!ll&&!rl&&r
26000
not defined $prev_state and $type == 3
!ll&&!rl&&r
26000
MC/DC0%0/3
not defined $prev_state and $type == 3 and $act eq "send"
not defined $prev_state $type == 3 $act eq "send"
Truth table25%1/4
not(A) and B and C
A= not defined $prev_stateB= $type == 3C= $act eq "send"
ABCresult
0XX0
10X0
1100
1111
210  
211 # Direction server->client
212 my $srv2cln = ( $self->{type} == SERVER && $act eq 'send' )
213 260 ▶ || ( $self->{type} == CLIENT && $act eq 'recv' );
Condition100%9/9
$self->{'type'} == 2 && $act eq 'send' || $self->{'type'} == 1 && $act eq 'recv'
l!l&&r!l&&!r
7480106
$self->{"type"} == 2 and $act eq "send"
!ll&&!rl&&r
1365074
$self->{"type"} == 1 and $act eq "recv"
!ll&&!rl&&r
505680
MC/DC75%3/4
$self->{'type'} == 2 && $act eq 'send' || $self->{'type'} == 1 && $act eq 'recv'
$self->{"type"} == 2 $act eq "send" $self->{"type"} == 1 $act eq "recv"
Truth table57%4/7
A and B || C and D
A= $self->{"type"} == 2B= $act eq "send"C= $self->{"type"} == 1D= $act eq "recv"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
214  
215 # Direction client->server
216 my $cln2srv = ( $self->{type} == SERVER && $act eq 'recv' )
217 260 ▶ || ( $self->{type} == CLIENT && $act eq 'send' );
Condition100%9/9
$self->{'type'} == 2 && $act eq 'recv' || $self->{'type'} == 1 && $act eq 'send'
l!l&&r!l&&!r
5056154
$self->{"type"} == 2 and $act eq "recv"
!ll&&!rl&&r
1367450
$self->{"type"} == 1 and $act eq "send"
!ll&&!rl&&r
748056
MC/DC75%3/4
$self->{'type'} == 2 && $act eq 'recv' || $self->{'type'} == 1 && $act eq 'send'
$self->{"type"} == 2 $act eq "recv" $self->{"type"} == 1 $act eq "send"
Truth table57%4/7
A and B || C and D
A= $self->{"type"} == 2B= $act eq "recv"C= $self->{"type"} == 1D= $act eq "send"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
218  
219 # Do we expect CONTINUATION after this frame?
220 260 ▶ my $pending = ( $type == HEADERS || $type == PUSH_PROMISE )
Condition83%5/6
($type == 1 || $type == 5) && !($flags & 4)
!ll&&!rl&&r
1101473
$type == 1 or $type == 5
l!l&&r!l&&!r
1500110
MC/DC66%2/3
($type == 1 || $type == 5) && !($flags & 4)
$type == 1 $type == 5 !($flags & 4)
Truth table60%3/5
A or B && not(C)
A= $type == 1B= $type == 5C= !($flags & 4)
ABCresult
00X0
1X00
0100
1X11
0111
221 && !( $flags & END_HEADERS );
222  
223 #tracer->debug(
224 # sprintf "\e[0;31mStream state: frame %s is %s%s on %s stream %i\e[m\n",
225 # const_name( "frame_types", $type ),
226 # $act,
227 # $pending ? "*" : "",
228 # const_name( "states", $prev_state ),
229 # $promised_sid || $stream_id,
230 #);
231  
232 # Wait until all CONTINUATION frames arrive
233 260 ▶ if ( my $ps = $self->stream_pending_state($stream_id) ) {
Branch: 7 branches
BranchTrueFalseTotal
if (my $ps = $self->stream_pending_state($stream_id)) { } 3 257 260
elsif ($type == 9) { } 0 257 257
elsif ($prev_state == 1) { } 80 177 257
elsif ($prev_state == 3) { } 13 164 177
elsif ($prev_state == 2) { } 0 164 164
elsif ($prev_state == 4) { } 159 5 164
elsif ($prev_state == 5) { } 5 0 5
234 3 ▶ if ( $type != CONTINUATION ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type != 9) { } 0 3 3
elsif ($flags & 4) { } 3 0 3
235 0 tracer->error(
236 sprintf "invalid frame type %s. Expected CONTINUATION frame\n",
237 const_name( "frame_types", $type )
238 );
239 0 $self->error(PROTOCOL_ERROR);
240 }
241 elsif ( $flags & END_HEADERS ) {
242 3 ▶ $self->stream_promised_sid( $stream_id, undef ) if $promised_sid;
Branch: 1 branch
BranchTrueFalseTotal
if $promised_sid 0 3 3
243 3 ▶ $self->stream_pending_state( $promised_sid || $stream_id, undef );
Condition33%1/3
$promised_sid || $stream_id
l!l&&r!l&&!r
030
MC/DC0%0/2
$promised_sid || $stream_id
$promised_sid $stream_id
Truth table33%1/3
A || B
A= $promised_sidB= $stream_id
ABresult
1X1
011
000
244 3 ▶ $self->stream_state( $promised_sid || $stream_id, $ps );
Condition33%1/3
$promised_sid || $stream_id
l!l&&r!l&&!r
030
MC/DC0%0/2
$promised_sid || $stream_id
$promised_sid $stream_id
Truth table33%1/3
A || B
A= $promised_sidB= $stream_id
ABresult
1X1
011
000
245 }
246 }
247  
248 # Unexpected CONTINUATION frame
249 elsif ( $type == CONTINUATION ) {
250 0 tracer->error("Unexpected CONTINUATION frame\n");
251 0 $self->error(PROTOCOL_ERROR);
252 }
253  
254 # State machine
255 # IDLE
256 elsif ( $prev_state == IDLE ) {
257 80 ▶ if ( $type == HEADERS && $cln2srv ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type == 1 and $cln2srv) { } 79 1 80
elsif ($type == 5 and $srv2cln) { } 0 1 1
elsif ($type == 3 and $act eq 'send') { } 0 1 1
elsif ($type != 2) { } 0 1 1
Condition66%2/3
$type == 1 and $cln2srv
!ll&&!rl&&r
1079
MC/DC50%1/2
$type == 1 and $cln2srv
$type == 1 $cln2srv
Truth table66%2/3
A and B
A= $type == 1B= $cln2srv
ABresult
0X0
100
111
258 79 ▶ $self->stream_state( $stream_id,
Branch: 1 branch
BranchTrueFalseTotal
$flags & 1 ? : 73 6 79
259 ( $flags & END_STREAM ) ? HALF_CLOSED : OPEN, $pending );
260 }
261 ▶ elsif ( $type == PUSH_PROMISE && $srv2cln ) {
Condition33%1/3
$type == 5 and $srv2cln
!ll&&!rl&&r
100
MC/DC0%0/2
$type == 5 and $srv2cln
$type == 5 $srv2cln
Truth table33%1/3
A and B
A= $type == 5B= $srv2cln
ABresult
0X0
100
111
262 0 $self->stream_state( $promised_sid, RESERVED, $pending );
263 0 ▶ $self->stream_promised_sid( $stream_id, undef )
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 4 0 0 0
264 if $flags & END_HEADERS;
265 }
266  
267 # first frame in stream is invalid, so state is yet IDLE
268 ▶ elsif ( $type == RST_STREAM && $act eq 'send' ) {
Condition33%1/3
$type == 3 and $act eq "send"
!ll&&!rl&&r
100
MC/DC0%0/2
$type == 3 and $act eq "send"
$type == 3 $act eq "send"
Truth table33%1/3
A and B
A= $type == 3B= $act eq "send"
ABresult
0X0
100
111
269 0 tracer->notice('send RST_STREAM on IDLE state. possible bug?');
270 0 $self->stream_state( $stream_id, CLOSED );
271 }
272 elsif ( $type != PRIORITY ) {
273 0 tracer->error(
274 sprintf "invalid frame type %s for current stream state %s\n",
275 const_name( "frame_types", $type ),
276 const_name( "states", $prev_state )
277 );
278 0 $self->error(PROTOCOL_ERROR);
279 }
280 }
281  
282 # OPEN
283 elsif ( $prev_state == OPEN ) {
284 13 ▶ if ( ( $flags & END_STREAM )
Branch: 3 branches
BranchTrueFalseTotal
if ($flags & 1 and $type == 0 || $type == 1) { } 4 9 13
elsif ($type == 3) { } 0 9 9
elsif ($type == 1 and not $pending and $self->stream_trailer($stream_id)) { } 0 18 18
Condition50%3/6
$flags & 1 and $type == 0 || $type == 1
!ll&&!rl&&r
904
$type == 0 or $type == 1
l!l&&r!l&&!r
400
MC/DC33%1/3
$flags & 1 and $type == 0 || $type == 1
$flags & 1 $type == 0 $type == 1
Truth table50%2/4
A and B or C
A= $flags & 1B= $type == 0C= $type == 1
ABCresult
0XX0
1000
11X1
1011
285 && ( $type == DATA || $type == HEADERS ) )
286 {
287 4 $self->stream_state( $stream_id, HALF_CLOSED, $pending );
288 }
289 elsif ( $type == RST_STREAM ) {
290 0 $self->stream_state( $stream_id, CLOSED );
291 }
292 ▶ elsif ($type == HEADERS
Condition33%2/6
$type == 1 and not $pending and $self->stream_trailer($stream_id)
!ll&&!rl&&r
900
$type == 1 and not $pending
!ll&&!rl&&r
900
MC/DC0%0/3
$type == 1 and not $pending and $self->stream_trailer($stream_id)
$type == 1 not $pending $self->stream_trailer($stream_id)
Truth table25%1/4
A and not(B) and C
A= $type == 1B= not $pendingC= $self->stream_trailer($stream_id)
ABCresult
0XX0
10X0
1100
1111
293 && !$pending
294 && $self->stream_trailer($stream_id) )
295 {
296 0 tracer->error("expected END_STREAM flag for trailer HEADERS frame");
297 0 $self->error(PROTOCOL_ERROR);
298 }
299 }
300  
301 # RESERVED (local/remote)
302 elsif ( $prev_state == RESERVED ) {
303 0 ▶ if ( $type == RST_STREAM ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type == 3) { } 0 0 0
elsif ($type == 1 and $srv2cln) { } 0 0 0
elsif ($type != 2 and $cln2srv) { } 0 0 0
304 0 $self->stream_state( $stream_id, CLOSED );
305 }
306 ▶ elsif ( $type == HEADERS && $srv2cln ) {
Condition0%0/3
$type == 1 and $srv2cln
!ll&&!rl&&r
000
MC/DC0%0/2
$type == 1 and $srv2cln
$type == 1 $srv2cln
Truth table0%0/3
A and B
A= $type == 1B= $srv2cln
ABresult
0X0
100
111
307 0 ▶ $self->stream_state( $stream_id,
Branch: 1 branch
BranchTrueFalseTotal
$flags & 1 ? : 0 0 0
308 ( $flags & END_STREAM ) ? CLOSED : HALF_CLOSED, $pending );
309 }
310 ▶ elsif ( $type != PRIORITY && $cln2srv ) {
Condition0%0/3
$type != 2 and $cln2srv
!ll&&!rl&&r
000
MC/DC0%0/2
$type != 2 and $cln2srv
$type != 2 $cln2srv
Truth table0%0/3
A and B
A= $type != 2B= $cln2srv
ABresult
0X0
100
111
311 0 tracer->error("invalid frame $type for state RESERVED");
312 0 $self->error(PROTOCOL_ERROR);
313 }
314 }
315  
316 # HALF_CLOSED (local/remote)
317 elsif ( $prev_state == HALF_CLOSED ) {
318 159 ▶ if ( ( $type == RST_STREAM )
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 3 or $flags & 1 and $srv2cln) { } 71 88 159
elsif (not grep({$type == $_;} 8, 2) and $cln2srv) { } 0 88 88
Condition83%5/6
$type == 3 or $flags & 1 and $srv2cln
l!l&&r!l&&!r
106188
$flags & 1 and $srv2cln
!ll&&!rl&&r
88061
MC/DC66%2/3
$type == 3 or $flags & 1 and $srv2cln
$type == 3 $flags & 1 $srv2cln
Truth table75%3/4
A or B and C
A= $type == 3B= $flags & 1C= $srv2cln
ABCresult
1XX1
0111
00X0
0100
319 || ( ( $flags & END_STREAM ) && $srv2cln ) )
320 {
321 71 $self->stream_state( $stream_id, CLOSED, $pending );
322 }
323 176 ▶ elsif ( ( !grep { $type == $_ } ( WINDOW_UPDATE, PRIORITY ) )
Condition33%1/3
not grep({$type == $_;} 8, 2) and $cln2srv
!ll&&!rl&&r
0880
MC/DC0%0/2
not grep({$type == $_;} 8, 2) and $cln2srv
not grep({$type == $_;} 8, 2) $cln2srv
Truth table33%1/3
not(A) and B
A= not grep({$type == $_;} 8, 2)B= $cln2srv
ABresult
0X0
100
111
324 && $cln2srv )
325 {
326 0 tracer->error( sprintf "invalid frame %s for state HALF CLOSED\n",
327 const_name( "frame_types", $type ) );
328 0 $self->error(PROTOCOL_ERROR);
329 }
330 }
331  
332 # CLOSED
333 elsif ( $prev_state == CLOSED ) {
334 5 ▶ if ( $type != PRIORITY && ( $type != WINDOW_UPDATE && $cln2srv ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type != 2 and ($type != 8 and $cln2srv)) 0 5 5
Condition33%2/6
$type != 2 and ($type != 8 and $cln2srv)
!ll&&!rl&&r
050
$type != 8 and $cln2srv
!ll&&!rl&&r
050
MC/DC0%0/3
$type != 2 and ($type != 8 and $cln2srv)
$type != 2 $type != 8 $cln2srv
Truth table25%1/4
A and B and C
A= $type != 2B= $type != 8C= $cln2srv
ABCresult
0XX0
10X0
1100
1111
335  
336 0 tracer->error("stream is closed\n");
337 0 $self->error(STREAM_CLOSED);
338 }
339 }
340 else {
341 0 tracer->error("oops!\n");
342 0 $self->error(INTERNAL_ERROR);
343 }
344 }
345  
346 # TODO: move this to some other module
347 75 ▶sub send_headers {
Subroutine send_headers: called CC=5 SCAR=16.1
Pod undocumented
348 75 my ( $self, $stream_id, $headers, $end ) = @_;
349 75 my $max_size = $self->enc_setting(SETTINGS_MAX_FRAME_SIZE);
350  
351 75 my $header_block = headers_encode( $self->encode_context, $headers );
352  
353 75 ▶ my $flags = $end ? END_STREAM : 0;
Branch: 1 branch
BranchTrueFalseTotal
$end ? : 39 36 75
354 75 ▶ $flags |= END_HEADERS if length($header_block) <= $max_size;
Branch: 1 branch
BranchTrueFalseTotal
if length $header_block <= $max_size 74 1 75
355  
356 75 $self->enqueue( HEADERS, $flags, $stream_id,
357 { hblock => \substr( $header_block, 0, $max_size, '' ) } );
358 75 ▶ while ( length($header_block) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $header_block > 0) 1 75 76
359 1 ▶ my $flags = length($header_block) <= $max_size ? END_HEADERS : 0;
Branch: 1 branch
BranchTrueFalseTotal
length $header_block <= $max_size ? : 1 0 1
360 1 $self->enqueue( CONTINUATION, $flags,
361 $stream_id, \substr( $header_block, 0, $max_size, '' ) );
362 }
363 }
364  
365 0 ▶sub send_pp_headers {
Subroutine send_pp_headers: not called CC=4 SCAR=30.0
Pod undocumented
366 0 my ( $self, $stream_id, $promised_id, $headers ) = @_;
367 0 my $max_size = $self->enc_setting(SETTINGS_MAX_FRAME_SIZE);
368  
369 0 my $header_block = headers_encode( $self->encode_context, $headers );
370  
371 0 ▶ my $flags = length($header_block) <= $max_size ? END_HEADERS : 0;
Branch: 1 branch
BranchTrueFalseTotal
length $header_block <= $max_size ? : 0 0 0
372  
373 0 $self->enqueue( PUSH_PROMISE, $flags, $stream_id,
374 [ $promised_id, \substr( $header_block, 0, $max_size - 4, '' ) ] );
375  
376 0 ▶ while ( length($header_block) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $header_block > 0) 0 0 0
377 0 ▶ my $flags = length($header_block) <= $max_size ? END_HEADERS : 0;
Branch: 1 branch
BranchTrueFalseTotal
length $header_block <= $max_size ? : 0 0 0
378 0 $self->enqueue( CONTINUATION, $flags,
379 $stream_id, \substr( $header_block, 0, $max_size, '' ) );
380 }
381 }
382  
383 43 ▶sub send_data {
Subroutine send_data: called CC=10 SCAR=23.0
Pod undocumented
384 43 my ( $self, $stream_id, $chunk, $end ) = @_;
385 43 my $data = $self->stream_blocked_data($stream_id);
386 43 ▶ $data .= defined $chunk ? $chunk : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $chunk ? : 13 30 43
387 43 ▶ $self->stream_end( $stream_id, $end ) if defined $end;
Branch: 1 branch
BranchTrueFalseTotal
if defined $end 31 12 43
388 43 $end = $self->stream_end($stream_id);
389  
390 43 while (1) {
391 47 my $l = length($data);
392 47 my $size = $self->enc_setting(SETTINGS_MAX_FRAME_SIZE);
393 47 for ( $l, $self->fcw_send, $self->stream_fcw_send($stream_id) ) {
394 141 ▶ $size = $_ if $size > $_;
Branch: 1 branch
BranchTrueFalseTotal
if $size > $_ 45 96 141
395 }
396  
397 # Flow control
398 47 ▶ last if $l != 0 && $size <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $l != 0 and $size <= 0 1 46 47
Condition100%3/3
$l != 0 and $size <= 0
!ll&&!rl&&r
29171
MC/DC100%2/2
$l != 0 and $size <= 0
$l != 0 $size <= 0
Truth table100%3/3
A and B
A= $l != 0B= $size <= 0
ABresult
0X0
100
111
399 46 $self->fcw_send( -$size );
400 46 $self->stream_fcw_send( $stream_id, -$size );
401  
402 46 ▶ $self->enqueue(
Branch: 1 branch
BranchTrueFalseTotal
$end && $l == $size ? : 31 15 46
Condition100%3/3
$end and $l == $size
!ll&&!rl&&r
11431
MC/DC100%2/2
$end and $l == $size
$end $l == $size
Truth table100%3/3
A and B
A= $endB= $l == $size
ABresult
0X0
100
111
403 DATA, $end && $l == $size ? END_STREAM : 0,
404 $stream_id, \substr( $data, 0, $size, '' )
405 );
406 46 ▶ last if $l == $size;
Branch: 1 branch
BranchTrueFalseTotal
if $l == $size 42 4 46
407 }
408 43 $self->stream_blocked_data( $stream_id, $data );
409 }
410  
411 1 ▶sub send_blocked {
Subroutine send_blocked: called CC=2 SCAR=6.9
Pod undocumented
412 1 my $self = shift;
413 1 for my $stream_id ( keys %{ $self->{streams} } ) {
414 3 $self->stream_send_blocked($stream_id);
415 }
416 }
417  
418 2 ▶sub error {
Subroutine error: called CC=4 SCAR=14.0
Pod undocumented
419 2 my $self = shift;
420 2 ▶ if ( @_ && !$self->{shutdown} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and not $self->{"shutdown"}) 1 1 2
Condition66%2/3
@_ and not $self->{"shutdown"}
!ll&&!rl&&r
011
MC/DC50%1/2
@_ and not $self->{"shutdown"}
@_ not $self->{"shutdown"}
Truth table66%2/3
A and not(B)
A= @_B= not $self->{"shutdown"}
ABresult
0X0
100
111
421 1 $self->{error} = shift;
422 1 ▶ $self->{on_error}->( $self->{error} ) if exists $self->{on_error};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"on_error"} 1 0 1
423 1 $self->finish;
424 }
425 2 $self->{error};
426 }
427  
428 0 ▶sub setting {
Subroutine setting: not called CC=1 SCAR=6.9
Pod undocumented
429 0 require Carp;
430 0 Carp::confess("setting is deprecated\n");
431 }
432  
433 694 ▶sub _setting {
Subroutine _setting: called CC=3 SCAR=11.0
434 694 my ( $ctx, $self, $setting ) = @_;
435 694 my $s = $self->{$ctx}->{settings};
436 694 ▶ return undef unless exists $s->{$setting};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $s->{$setting} 0 694 694
437 694 ▶ $s->{$setting} = pop if @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 3 20 674 694
438 694 $s->{$setting};
439 }
440  
441 249 ▶sub enc_setting {
Subroutine enc_setting: called CC=1 SCAR=0.0
Pod undocumented
442 249 _setting( 'encode_ctx', @_ );
443 }
444  
445 445 ▶sub dec_setting {
Subroutine dec_setting: called CC=1 SCAR=0.0
Pod undocumented
446 445 _setting( 'decode_ctx', @_ );
447 }
448  
449 36 ▶sub accept_settings {
Subroutine accept_settings: called CC=1 SCAR=0.0
Pod undocumented
450 36 my $self = shift;
451 36 $self->enqueue( SETTINGS, ACK, 0, {} );
452 }
453  
454 # Flow control windown of connection
455 144 ▶sub _fcw {
Subroutine _fcw: called CC=2 SCAR=6.9
456 144 my $dir = shift;
457 144 my $self = shift;
458  
459 144 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 97 47 144
460 97 $self->{$dir} += shift;
461 97 tracer->debug( "$dir now is " . $self->{$dir} . "\n" );
462 }
463 144 $self->{$dir};
464 }
465  
466 94 ▶sub fcw_send {
Subroutine fcw_send: called CC=1 SCAR=0.0
Pod undocumented
467 94 _fcw( 'fcw_send', @_ );
468 }
469  
470 50 ▶sub fcw_recv {
Subroutine fcw_recv: called CC=1 SCAR=0.0
Pod undocumented
471 50 _fcw( 'fcw_recv', @_ );
472 }
473  
474 1 ▶sub fcw_update {
Subroutine fcw_update: called CC=1 SCAR=0.0
Pod undocumented
475 1 my $self = shift;
476  
477 # TODO: check size of data in memory
478 1 my $size = $self->dec_setting(SETTINGS_INITIAL_WINDOW_SIZE);
479 1 tracer->debug("update fcw recv of connection with $size b.\n");
480 1 $self->fcw_recv($size);
481 1 $self->enqueue( WINDOW_UPDATE, 0, 0, $size );
482 }
483  
484 0 ▶sub fcw_initial_change {
Subroutine fcw_initial_change: not called CC=3 SCAR=24.8
Pod undocumented
485 0 my ( $self, $size ) = @_;
486 0 my $prev_size = $self->enc_setting(SETTINGS_INITIAL_WINDOW_SIZE);
487 0 my $diff = $size - $prev_size;
488 0 tracer->debug(
489 "Change flow control window on not closed streams with diff $diff\n");
490 0 for my $stream_id ( keys %{ $self->{streams} } ) {
491 0 ▶ next if $self->stream_state($stream_id) == CLOSED;
Branch: 1 branch
BranchTrueFalseTotal
if $self->stream_state($stream_id) == 5 0 0 0
492 0 $self->stream_fcw_send( $stream_id, $diff );
493 }
494 }
495  
496 1 ▶sub ack_ping {
Subroutine ack_ping: called CC=1 SCAR=0.0
Pod undocumented
497 1 my ( $self, $payload_ref ) = @_;
498 1 $self->enqueue_first( PING, ACK, 0, $payload_ref );
499 }
500  
501 1 ▶sub send_ping {
Subroutine send_ping: called CC=3 SCAR=14.2
Pod undocumented
502 1 my ( $self, $payload ) = @_;
503 1 ▶ if ( !defined $payload ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $payload) { } 0 1 1
elsif (length $payload != 8) { } 0 1 1
504 0 $payload = pack "C*", map { rand(256) } 1 .. PING_PAYLOAD_SIZE;
505 }
506 elsif ( length($payload) != PING_PAYLOAD_SIZE ) {
507 0 $payload = sprintf "%*.*s",
508 -PING_PAYLOAD_SIZE(), PING_PAYLOAD_SIZE, $payload;
509 }
510 1 $self->enqueue( PING, 0, 0, \$payload );
511 }
512  
513 13 1;
↑ Summary HTTP2/HeaderCompression.pm »