blib/lib/Unblock/HTTP2/_nghttp2.pm

filter: Statementstmt 81.1% 99 / 122 Branchbran 47.3% 36 / 76 Conditioncond 26.6% 12 / 45 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 84.6% 22 / 26 Podpod 0.0% 0 / 1 totaltotal 57.8% 169 / 292 CC 57 SCAR 30.4
CC
57
Cov
60%
submit_response
110.0
submit_headers
42.0
submit_priority_update
13.3
CRAP 21.0
« blib/lib/Unblock/HTTP2/Server.pm ↑ Summary blib/lib/Unblock/HTTP2/_Connection.pm »
1 package Unblock::HTTP2::_nghttp2;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 29 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 29 our $VERSION = '0.12';
8  
9 29 require XSLoader;
10 29 XSLoader::load('Unblock::HTTP2', $VERSION);
11  
12 92 ▶sub available { return _available() ? 1 : 0 }
Subroutine available: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
_available() ? : 92 0 92
13  
14 29 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
15 29 SETTINGS_HEADER_TABLE_SIZE => 1,
16 SETTINGS_ENABLE_PUSH => 2,
17 SETTINGS_MAX_CONCURRENT_STREAMS => 3,
18 SETTINGS_INITIAL_WINDOW_SIZE => 4,
19 SETTINGS_MAX_FRAME_SIZE => 5,
20 SETTINGS_MAX_HEADER_LIST_SIZE => 6,
21 SETTINGS_ENABLE_CONNECT_PROTOCOL => 8,
22 SETTINGS_NO_RFC7540_PRIORITIES => 9,
23 29 };
24  
25 package Unblock::HTTP2::_nghttp2::Session;
26  
27 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 29 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 92 ▶sub _callbacks {
Subroutine _callbacks: called CC=6 SCAR=19.6
32 92 my ($callbacks) = @_;
33 92 ▶ $callbacks ||= {};
Condition50%1/2
$callbacks ||= {}
l!l
920
MC/DC0%0/1
$callbacks ||= {}
$callbacks
Truth table50%1/2
A
A= $callbacks
Aresult
11
00
34 92 ▶ croak 'callbacks must be a hash reference' unless ref($callbacks) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callbacks eq "HASH" 0 92 92
35 92 for my $name (keys %$callbacks) {
36 460 my $cb = $callbacks->{$name};
37 460 ▶ croak "callback $name must be a coderef"
Branch: 1 branch
BranchTrueFalseTotal
if defined $cb and ref $cb ne "CODE" 0 460 460
Condition33%1/3
defined $cb and ref $cb ne "CODE"
!ll&&!rl&&r
04600
MC/DC0%0/2
defined $cb and ref $cb ne "CODE"
defined $cb ref $cb ne "CODE"
Truth table33%1/3
A and B
A= defined $cbB= ref $cb ne "CODE"
ABresult
0X0
100
111
38 if defined($cb) && ref($cb) ne 'CODE';
39 }
40 92 return $callbacks;
41 }
42  
43 92 ▶sub _max_header_list_size {
Subroutine _max_header_list_size: called CC=6 SCAR=22.8
44 92 my ($operation, $args) = @_;
45 my $limit = exists($args->{max_header_list_size})
46 ? delete($args->{max_header_list_size})
47 92 ▶ : 65_536;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'max_header_list_size'} ? : 92 0 92
48 92 ▶ croak "$operation: max_header_list_size must be a positive integer"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $limit and not ref $limit and "$limit" =~ /\A[0-9]+\z/ and $limit > 0 0 92 92
Condition33%3/9
defined $limit and not ref $limit and "$limit" =~ /\A[0-9]+\z/ and $limit > 0
!ll&&!rl&&r
0092
defined $limit and not ref $limit and "$limit" =~ /\A[0-9]+\z/
!ll&&!rl&&r
0092
defined $limit and not ref $limit
!ll&&!rl&&r
0092
MC/DC0%0/4
defined $limit and not ref $limit and "$limit" =~ /\A[0-9]+\z/ and $limit > 0
defined $limit not ref $limit "$limit" =~ /\A[0-9]+\z/ $limit > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $limitB= not ref $limitC= "$limit" =~ /\A[0-9]+\z/D= $limit > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
49 unless defined($limit) && !ref($limit)
50 && "$limit" =~ /\A[0-9]+\z/ && $limit > 0;
51 92 return 0 + $limit;
52 }
53  
54 50 ▶sub new_client {
Subroutine new_client: called CC=2 SCAR=7.0
55 50 my ($class, %args) = @_;
56 50 my $callbacks = _callbacks(delete($args{callbacks}));
57 50 my $max_header_list_size = _max_header_list_size('new_client()', \%args);
58 50 ▶ croak 'new_client(): unknown options: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 50 50
59 if %args;
60 50 return $class->_new_client_xs($callbacks, $max_header_list_size);
61 }
62  
63 42 ▶sub new_server {
Subroutine new_server: called CC=2 SCAR=7.0
64 42 my ($class, %args) = @_;
65 42 my $callbacks = _callbacks(delete($args{callbacks}));
66 42 my $max_header_list_size = _max_header_list_size('new_server()', \%args);
67 42 ▶ croak 'new_server(): unknown options: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 42 42
68 if %args;
69 42 return $class->_new_server_xs($callbacks, $max_header_list_size);
70 }
71  
72 0 ▶sub send_connection_preface {
Subroutine send_connection_preface: not called CC=1 SCAR=6.9
73 0 my ($self, %settings) = @_;
74 0 return $self->submit_settings(\%settings);
75 }
76  
77 82 ▶sub _body_provider {
Subroutine _body_provider: called CC=5 SCAR=16.1
78 82 my ($body) = @_;
79 82 ▶ return unless defined $body;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 29 53 82
80 53 ▶ return $body if ref($body) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $body eq "CODE" 14 39 53
81 39 ▶ croak 'body must be a byte string or coderef' if ref($body);
Branch: 1 branch
BranchTrueFalseTotal
if ref $body 0 39 39
82 39 ▶ return if !length($body);
Branch: 1 branch
BranchTrueFalseTotal
unless length $body 2 37 39
83  
84 37 my $offset = 0;
85 37 my $length = length($body);
86 44 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
87 44 my ($stream_id, $max_length) = @_;
88 44 my $left = $length - $offset;
89 44 ▶ my $take = $left < $max_length ? $left : $max_length;
Branch: 1 branch
BranchTrueFalseTotal
$left < $max_length ? : 36 8 44
90 44 my $chunk = substr($body, $offset, $take);
91 44 $offset += $take;
92 44 ▶ return ($chunk, $offset >= $length ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$offset >= $length ? : 37 7 44
93 37 };
94 }
95  
96 0 ▶sub _submit_request_xs {
Subroutine _submit_request_xs: not called CC=1 SCAR=6.9
97 0 my ($self, $headers, $body) = @_;
98 0 my $provider = _body_provider($body);
99 0 return $self->_submit_request_native($headers, $provider);
100 }
101  
102 50 ▶sub _submit_request_uniform_xs {
Subroutine _submit_request_uniform_xs: called CC=1 SCAR=0.0
103 50 my ($self, $message, $body) = @_;
104 50 my $provider = _body_provider($body);
105 50 return $self->_submit_request_uniform_native($message, $provider);
106 }
107  
108 32 ▶sub submit_response_uniform {
Subroutine submit_response_uniform: called CC=4 SCAR=13.9
109 32 my ($self, $stream_id, $message, %args) = @_;
110 32 my $body = delete($args{body});
111 32 my $data_callback = delete($args{data_callback});
112 32 delete $args{callback_data};
113 32 ▶ croak 'submit_response_uniform(): unknown options: '
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 32 32
114 . join(', ', sort keys %args)
115 if %args;
116  
117 32 ▶ my $provider = defined($data_callback)
Branch: 1 branch
BranchTrueFalseTotal
defined $data_callback ? : 3 29 32
118 ? _body_provider($data_callback)
119 : _body_provider($body);
120  
121 32 ▶ return $provider
Branch: 1 branch
BranchTrueFalseTotal
$provider ? : 30 2 32
122 ? $self->_submit_response_uniform_streaming_native(
123 $stream_id, $message, $provider,
124 )
125 : $self->_submit_response_uniform_no_body_native(
126 $stream_id, $message,
127 );
128 }
129  
130 3 ▶sub submit_response_headers_uniform {
Subroutine submit_response_headers_uniform: called CC=4 SCAR=14.9
131 3 my ($self, $stream_id, $message, %args) = @_;
132 3 ▶ my $end_stream = delete($args{end_stream}) || 0;
Condition50%1/2
delete $args{'end_stream'} || 0
l!l
03
MC/DC0%0/1
delete $args{'end_stream'} || 0
delete $args{'end_stream'}
Truth table50%1/2
A
A= delete $args{'end_stream'}
Aresult
11
00
133 3 ▶ croak 'submit_response_headers_uniform(): unknown options: '
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 3 3
134 . join(', ', sort keys %args)
135 if %args;
136  
137 3 ▶ return $self->_submit_response_headers_uniform_native(
Branch: 1 branch
BranchTrueFalseTotal
$end_stream ? : 0 3 3
138 $stream_id, $message, $end_stream ? 1 : 0,
139 );
140 }
141  
142 0 ▶sub submit_response {
Subroutine submit_response: not called CC=10 SCAR=47.0
143 0 my ($self, $stream_id, %args) = @_;
144 0 ▶ my $status = exists($args{status}) ? delete($args{status}) : 200;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'status'} ? : 0 0 0
145 0 ▶ my $headers = delete($args{headers}) || [];
Condition0%0/2
delete $args{'headers'} || []
l!l
00
MC/DC0%0/1
delete $args{'headers'} || []
delete $args{'headers'}
Truth table0%0/2
A
A= delete $args{'headers'}
Aresult
11
00
146 0 my $body = delete $args{body};
147 0 my $data_callback = delete $args{data_callback};
148 0 delete $args{callback_data};
149 0 ▶ croak 'submit_response(): unknown options: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 0 0
150 if %args;
151 0 ▶ croak 'submit_response(): headers must be an array reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $headers eq "ARRAY" 0 0 0
152 unless ref($headers) eq 'ARRAY';
153 0 ▶ croak 'submit_response(): status must be an integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status and not ref $status and $status =~ /\A[0-9]+\z/ 0 0 0
Condition0%0/6
defined $status and not ref $status and $status =~ /\A[0-9]+\z/
!ll&&!rl&&r
000
defined $status and not ref $status
!ll&&!rl&&r
000
MC/DC0%0/3
defined $status and not ref $status and $status =~ /\A[0-9]+\z/
defined $status not ref $status $status =~ /\A[0-9]+\z/
Truth table0%0/4
A and not(B) and C
A= defined $statusB= not ref $statusC= $status =~ /\A[0-9]+\z/
ABCresult
0XX0
10X0
1100
1111
154 unless defined($status) && !ref($status) && $status =~ /\A[0-9]+\z/;
155  
156 0 my @block = ([ ':status', "$status" ], @$headers);
157 0 ▶ my $provider = defined($data_callback)
Branch: 1 branch
BranchTrueFalseTotal
defined $data_callback ? : 0 0 0
158 ? _body_provider($data_callback)
159 : _body_provider($body);
160  
161 0 ▶ return $provider
Branch: 1 branch
BranchTrueFalseTotal
$provider ? : 0 0 0
162 ? $self->_submit_response_streaming_native($stream_id, \@block, $provider)
163 : $self->_submit_response_no_body_native($stream_id, \@block);
164 }
165  
166 0 ▶sub submit_headers {
Subroutine submit_headers: not called CC=6 SCAR=37.4
167 0 my ($self, $stream_id, %args) = @_;
168 0 ▶ my $headers = delete($args{headers}) || [];
Condition0%0/2
delete $args{'headers'} || []
l!l
00
MC/DC0%0/1
delete $args{'headers'} || []
delete $args{'headers'}
Truth table0%0/2
A
A= delete $args{'headers'}
Aresult
11
00
169 0 ▶ my $end_stream = delete($args{end_stream}) || 0;
Condition0%0/2
delete $args{'end_stream'} || 0
l!l
00
MC/DC0%0/1
delete $args{'end_stream'} || 0
delete $args{'end_stream'}
Truth table0%0/2
A
A= delete $args{'end_stream'}
Aresult
11
00
170 0 ▶ croak 'submit_headers(): unknown options: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 0 0
171 if %args;
172 0 ▶ croak 'submit_headers(): headers must be an array reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $headers eq "ARRAY" 0 0 0
173 unless ref($headers) eq 'ARRAY';
174 0 ▶ return $self->_submit_headers_native($stream_id, $headers, $end_stream ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$end_stream ? : 0 0 0
175 }
176  
177 5 ▶sub submit_trailer {
Subroutine submit_trailer: called CC=4 SCAR=14.6
178 5 my ($self, $stream_id, %args) = @_;
179 5 ▶ my $headers = delete($args{headers}) || [];
Condition50%1/2
delete $args{'headers'} || []
l!l
50
MC/DC0%0/1
delete $args{'headers'} || []
delete $args{'headers'}
Truth table50%1/2
A
A= delete $args{'headers'}
Aresult
11
00
180 5 ▶ croak 'submit_trailer(): unknown options: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 5 5
181 if %args;
182 5 ▶ croak 'submit_trailer(): headers must be an array reference'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $headers eq "ARRAY" 0 5 5
183 unless ref($headers) eq 'ARRAY';
184 5 return $self->_submit_trailer_native($stream_id, $headers);
185 }
186  
187 1 ▶sub submit_priority_update {
Subroutine submit_priority_update: called CC=8 SCAR=25.8
188 1 my ($self, $stream_id, $field_value) = @_;
189 1 ▶ croak 'submit_priority_update(): stream id must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $stream_id and not ref $stream_id and "$stream_id" =~ /\A[0-9]+\z/ and $stream_id > 0 0 1 1
Condition33%3/9
defined $stream_id and not ref $stream_id and "$stream_id" =~ /\A[0-9]+\z/ and $stream_id > 0
!ll&&!rl&&r
001
defined $stream_id and not ref $stream_id and "$stream_id" =~ /\A[0-9]+\z/
!ll&&!rl&&r
001
defined $stream_id and not ref $stream_id
!ll&&!rl&&r
001
MC/DC0%0/4
defined $stream_id and not ref $stream_id and "$stream_id" =~ /\A[0-9]+\z/ and $stream_id > 0
defined $stream_id not ref $stream_id "$stream_id" =~ /\A[0-9]+\z/ $stream_id > 0
Truth table20%1/5
A and not(B) and C and D
A= defined $stream_idB= not ref $stream_idC= "$stream_id" =~ /\A[0-9]+\z/D= $stream_id > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
190 unless defined($stream_id) && !ref($stream_id)
191 && "$stream_id" =~ /\A[0-9]+\z/ && $stream_id > 0;
192 1 ▶ croak 'submit_priority_update(): field value must be a scalar'
Branch: 1 branch
BranchTrueFalseTotal
if ref $field_value 0 1 1
193 if ref($field_value);
194 1 ▶ $field_value = '' unless defined $field_value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field_value 0 1 1
195 1 ▶ croak 'submit_priority_update(): field value exceeds 16380 bytes'
Branch: 1 branch
BranchTrueFalseTotal
if length $field_value > 16380 0 1 1
196 if length($field_value) > 16_380;
197 1 return $self->_submit_priority_update_native($stream_id, $field_value);
198 }
199  
200 6 ▶sub submit_ping {
Subroutine submit_ping: called CC=4 SCAR=17.1
201 6 my ($self, $opaque) = @_;
202 6 ▶ croak 'submit_ping(): opaque data must be exactly 8 bytes'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opaque and not ref $opaque and length $opaque == 8 0 6 6
Condition33%2/6
defined $opaque and not ref $opaque and length $opaque == 8
!ll&&!rl&&r
006
defined $opaque and not ref $opaque
!ll&&!rl&&r
006
MC/DC0%0/3
defined $opaque and not ref $opaque and length $opaque == 8
defined $opaque not ref $opaque length $opaque == 8
Truth table25%1/4
A and not(B) and C
A= defined $opaqueB= not ref $opaqueC= length $opaque == 8
ABCresult
0XX0
10X0
1100
1111
203 unless defined($opaque) && !ref($opaque) && length($opaque) == 8;
204 6 return $self->_submit_ping_native($opaque);
205 }
206  
207 6 ▶sub submit_goaway {
Subroutine submit_goaway: called CC=5 SCAR=17.0
208 6 my ($self, %args) = @_;
209 6 my $last_stream_id = delete $args{last_stream_id};
210 6 ▶ croak 'submit_goaway(): last_stream_id is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $last_stream_id 0 6 6
211 unless defined $last_stream_id;
212 6 ▶ my $error_code = exists($args{error_code}) ? delete($args{error_code}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'error_code'} ? : 6 0 6
213 my $debug_data = exists($args{debug_data})
214 ? delete($args{debug_data})
215 6 ▶ : delete($args{opaque_data});
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'debug_data'} ? : 6 0 6
216 6 ▶ croak 'submit_goaway(): unknown options: ' . join(', ', sort keys %args)
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 6 6
217 if %args;
218 6 return $self->_submit_goaway_native($last_stream_id, $error_code, $debug_data);
219 }
220  
221 5 ▶sub resume_stream {
Subroutine resume_stream: called CC=1 SCAR=0.0
222 5 my ($self, $stream_id) = @_;
223 5 $self->_clear_deferred($stream_id);
224 5 return $self->resume_data($stream_id);
225 }
226  
227 29 1;
« blib/lib/Unblock/HTTP2/Server.pm ↑ Summary blib/lib/Unblock/HTTP2/_Connection.pm »