lib/LightTCP/SSLclient.pm

filter: Statementstmt 36.0% 171 / 474 Branchbran 20.9% 49 / 234 Conditioncond 23.7% 29 / 122 MC/DCmcdc 16.1% 11 / 68 Subroutinesub 68.3% 41 / 60 Podpod 87.5% 28 / 32 totaltotal 33.2% 329 / 990 CC 170 SCAR 52.2
CC
170
Cov
30%
request
710.2
response
262.1
connect
255.4
CRAP 184.5
↑ Summary script/ssltest.pl »
1 package LightTCP::SSLclient;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use IO::Socket::SSL;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 our $VERSION = '1.06';
11  
12 6 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 our @EXPORT_OK = qw(
15 ECONNECT
16 EREQUEST
17 ERESPONSE
18 ETIMEOUT
19 ESSL
20 );
21  
22 6 our %EXPORT_TAGS = (
23 errors => [qw(ECONNECT EREQUEST ERESPONSE ETIMEOUT ESSL)],
24 );
25  
26 6 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ECONNECT => 1,
28 EREQUEST => 2,
29 ERESPONSE => 3,
30 ETIMEOUT => 4,
31 ESSL => 5,
32 6 };
33  
34 31 ▶sub new {
Subroutine new: called CC=12 SCAR=24.9
Pod undocumented
35 31 my ($class, %opts) = @_;
36 my $self = {
37 timeout => $opts{timeout} // 10,
38 insecure => $opts{insecure} // 0,
39 cert => $opts{cert} // undef,
40 verbose => $opts{verbose} // 0,
41 user_agent => $opts{user_agent} // 'LightTCP::SSLclient/'.$VERSION,
42 ssl_protocols => $opts{ssl_protocols} // ['TLSv1.2', 'TLSv1.3'],
43 ssl_ciphers => $opts{ssl_ciphers} // 'HIGH:!aNULL:!MD5:!RC4',
44 keep_alive => $opts{keep_alive} // 0,
45 buffer_size => $opts{buffer_size} // 8192,
46 max_redirects => $opts{max_redirects} // 5,
47 31 ▶ follow_redirects => $opts{follow_redirects} // 1,
Condition95%21/22
$opts{"timeout"} // 10
l!l
130
$opts{"insecure"} // 0
l!l
130
$opts{"cert"} // undef
l!l
031
$opts{"verbose"} // 0
l!l
724
$opts{"user_agent"} // 'LightTCP::SSLclient/' . $LightTCP::SSLclient::VERSION
l!l
130
$opts{"ssl_protocols"} // ["TLSv1.2", "TLSv1.3"]
l!l
130
$opts{"ssl_ciphers"} // "HIGH:!aNULL:!MD5:!RC4"
l!l
130
$opts{"keep_alive"} // 0
l!l
229
$opts{"buffer_size"} // 8192
l!l
229
$opts{"max_redirects"} // 5
l!l
229
$opts{"follow_redirects"} // 1
l!l
328
MC/DC100%1/1
$opts{"timeout"} // 10
$opts{"timeout"}
MC/DC100%1/1
$opts{"insecure"} // 0
$opts{"insecure"}
MC/DC0%0/1
$opts{"cert"} // undef
$opts{"cert"}
MC/DC100%1/1
$opts{"verbose"} // 0
$opts{"verbose"}
MC/DC100%1/1
$opts{"user_agent"} // 'LightTCP::SSLclient/' . $LightTCP::SSLclient::VERSION
$opts{"user_agent"}
MC/DC100%1/1
$opts{"ssl_protocols"} // ["TLSv1.2", "TLSv1.3"]
$opts{"ssl_protocols"}
MC/DC100%1/1
$opts{"ssl_ciphers"} // "HIGH:!aNULL:!MD5:!RC4"
$opts{"ssl_ciphers"}
MC/DC100%1/1
$opts{"keep_alive"} // 0
$opts{"keep_alive"}
MC/DC100%1/1
$opts{"buffer_size"} // 8192
$opts{"buffer_size"}
MC/DC100%1/1
$opts{"max_redirects"} // 5
$opts{"max_redirects"}
MC/DC100%1/1
$opts{"follow_redirects"} // 1
$opts{"follow_redirects"}
Truth table100%2/2
A
A= $opts{"timeout"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"insecure"}
Aresult
11
00
Truth table50%1/2
A
A= $opts{"cert"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"verbose"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"user_agent"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"ssl_protocols"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"ssl_ciphers"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"keep_alive"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"buffer_size"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"max_redirects"}
Aresult
11
00
Truth table100%2/2
A
A= $opts{"follow_redirects"}
Aresult
11
00
48 _socket => undef,
49 _connected => 0,
50 _target_host => undef,
51 _target_port => undef,
52 _proxy => undef,
53 _proxy_auth => undef,
54 _buffer => '',
55 _redirect_count=> 0,
56 _redirect_history => [],
57 };
58 31 bless $self, $class;
59 31 return $self;
60 }
61  
62 2 ▶sub _parse_proxy_address {
Subroutine _parse_proxy_address: called CC=4 SCAR=16.6
63 2 my ($proxy) = @_;
64  
65 2 ▶ if ($proxy =~ /^\[(.+)\]:(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy =~ /^\[(.+)\]:(\d+)$/) 0 2 2
66 0 return ($1, $2);
67 }
68  
69 2 ▶ if ($proxy =~ /^([^:]+):(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy =~ /^([^:]+):(\d+)$/) 0 2 2
70 0 return ($1, $2);
71 }
72  
73 2 ▶ if ($proxy =~ /^([^:]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy =~ /^([^:]+)$/) 0 2 2
74 0 return ($1, 8080);
75 }
76  
77 2 return (undef, undef);
78 }
79  
80 0 ▶sub _sanitize_credentials {
Subroutine _sanitize_credentials: not called CC=2 SCAR=17.9
81 0 my ($str) = @_;
82 0 ▶ return '' unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 0 0
83 0 $str =~ s/Basic\s+[A-Za-z0-9+\/=]+/Basic [REDACTED]/gi;
84 0 return $str;
85 }
86  
87 0 ▶sub _read_line_from_socket {
Subroutine _read_line_from_socket: not called CC=2 SCAR=17.9
88 0 my ($self, $socket, $timeout, $buffer_ref) = @_;
89 0 ▶ $$buffer_ref //= '';
Condition0%0/2
$$buffer_ref //= ""
l!l
00
MC/DC0%0/1
$$buffer_ref //= ""
$$buffer_ref
Truth table0%0/2
A
A= $$buffer_ref
Aresult
11
00
90 0 return _read_until_delimiter($self, $socket, $buffer_ref, $timeout, "\n");
91 }
92  
93 0 ▶sub _read_until_delimiter {
Subroutine _read_until_delimiter: not called CC=8 SCAR=42.8
94 0 my ($self, $socket, $buffer_ref, $timeout, $delim) = @_;
95 0 my $delim_len = length($delim);
96  
97 0 eval {
98 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 0 alarm $timeout;
100  
101 0 ▶ while ($$buffer_ref !~ /\Q$delim\E/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$buffer_ref =~ /\Q$delim\E/) 0 0 0
102 0 my $read;
103 0 my $res = sysread($socket, $read, $self->{buffer_size});
104 0 ▶ if (!defined $res) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $res) 0 0 0
105 0 alarm 0;
106 0 ▶ return undef if $!{EAGAIN} || $!{EWOULDBLOCK};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EAGAIN"} or $!{"EWOULDBLOCK"} 0 0 0
Condition0%0/3
$!{"EAGAIN"} or $!{"EWOULDBLOCK"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$!{"EAGAIN"} or $!{"EWOULDBLOCK"}
$!{"EAGAIN"} $!{"EWOULDBLOCK"}
Truth table0%0/3
A or B
A= $!{"EAGAIN"}B= $!{"EWOULDBLOCK"}
ABresult
1X1
011
000
107 0 return undef;
108 }
109 0 ▶ last if $res == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $res == 0 0 0 0
110 0 $$buffer_ref .= $read;
111 }
112  
113 0 alarm 0;
114 };
115 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
116 0 return undef;
117 }
118  
119 0 ▶ if ($$buffer_ref =~ /^([^\Q$delim\E]*)\Q$delim\E(.*)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$buffer_ref =~ /^([^\Q$delim\E]*)\Q$delim\E(.*)$/s) 0 0 0
120 0 $$buffer_ref = $2;
121 0 return $1 . $delim;
122 }
123 0 return undef;
124 }
125  
126 0 ▶sub _read_exact_bytes {
Subroutine _read_exact_bytes: not called CC=5 SCAR=34.0
127 0 my ($socket, $bytes, $timeout) = @_;
128 0 my $result = '';
129 0 my $buf;
130  
131 0 eval {
132 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
133 0 alarm $timeout;
134  
135 0 ▶ while (length($result) < $bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $result < $bytes) 0 0 0
136 0 my $read = sysread($socket, $buf, $bytes - length($result));
137 0 ▶ last unless defined $read && $read > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read and $read > 0 0 0 0
Condition0%0/3
defined $read and $read > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $read and $read > 0
defined $read $read > 0
Truth table0%0/3
A and B
A= defined $readB= $read > 0
ABresult
0X0
100
111
138 0 $result .= $buf;
139 }
140  
141 0 alarm 0;
142 };
143 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
144 0 return substr($result, 0, length($result));
145 }
146 0 return $result;
147 }
148  
149 0 ▶sub _hex_dump {
Subroutine _hex_dump: not called CC=1 SCAR=6.9
150 0 my ($data) = @_;
151 0 return join('', map { sprintf('%02x', ord($_)) } split(//, $data));
152 }
153  
154 2 ▶sub connect {
Subroutine connect: called CC=26 SCAR=55.4
Pod documented
155 2 my ($self, $target_host, $target_port, $proxy, $proxy_auth) = @_;
156  
157 2 my $timeout = $self->{timeout};
158 2 my $socket;
159  
160 my @debug;
161 2 my @errors;
162 2 ▶ push(@debug, "# === LightTCP::SSLclient::connect ===\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 1 1 2
163  
164 2 $self->{_target_host} = $target_host;
165 2 $self->{_target_port} = $target_port;
166 2 $self->{_proxy} = $proxy;
167 2 $self->{_proxy_auth} = $proxy_auth;
168 2 $self->{_buffer} = '';
169  
170 my %ssl_opts = (
171 SSL_verifycn_scheme => 'http',
172 SSL_verifycn_name => $target_host,
173 SSL_hostname => $target_host,
174 Timeout => $timeout,
175 SSL_protocols => $self->{ssl_protocols},
176 SSL_cipher_list => $self->{ssl_ciphers},
177 2 );
178  
179 2 ▶ if ($self->{insecure}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'insecure'}) { } 0 2 2
180 0 $ssl_opts{SSL_verify_mode} = IO::Socket::SSL::SSL_VERIFY_NONE;
181 } else {
182 2 $ssl_opts{SSL_verify_mode} = IO::Socket::SSL::SSL_VERIFY_PEER;
183 }
184  
185 2 ▶ if ($self->{cert} && -f $self->{cert}.'.key' && -f $self->{cert}.'.crt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cert"} and -f $self->{"cert"} . '.key' and -f $self->{"cert"} . '.crt') 0 2 2
Condition33%2/6
$self->{"cert"} and -f $self->{"cert"} . '.key' and -f $self->{"cert"} . '.crt'
!ll&&!rl&&r
200
$self->{"cert"} and -f $self->{"cert"} . '.key'
!ll&&!rl&&r
200
MC/DC0%0/3
$self->{"cert"} and -f $self->{"cert"} . '.key' and -f $self->{"cert"} . '.crt'
$self->{"cert"} -f $self->{"cert"} . '.key' -f $self->{"cert"} . '.crt'
Truth table25%1/4
A and B and C
A= $self->{"cert"}B= -f $self->{"cert"} . '.key'C= -f $self->{"cert"} . '.crt'
ABCresult
0XX0
10X0
1100
1111
186 0 $ssl_opts{SSL_key_file} = $self->{cert}.'.key';
187 0 $ssl_opts{SSL_cert_file} = $self->{cert}.'.crt';
188 }
189  
190 2 ▶ if ($self->{verbose}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 1 1 2
191 1 push(@debug, "# === ssl_opts ===\n");
192 1 foreach my $k (sort keys %ssl_opts) {
193 7 ▶ next if $k =~ /SSL_(key|cert)_file/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /SSL_(key|cert)_file/ 0 7 7
194 7 push(@debug, "- $k = $ssl_opts{$k}\n");
195 }
196 }
197  
198 2 ▶ if ($proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy) { } 2 0 2
199 2 my ($proxy_host, $proxy_port) = _parse_proxy_address($proxy);
200 2 ▶ unless ($proxy_host && $proxy_port) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($proxy_host and $proxy_port) 2 0 2
Condition33%1/3
$proxy_host and $proxy_port
!ll&&!rl&&r
200
MC/DC0%0/2
$proxy_host and $proxy_port
$proxy_host $proxy_port
Truth table33%1/3
A and B
A= $proxy_hostB= $proxy_port
ABresult
0X0
100
111
201 2 push(@errors, "- ERROR: Invalid proxy address format: $proxy\n");
202 2 return (0, \@errors, \@debug, ECONNECT);
203 }
204  
205 0 ▶ push(@debug, "# Connecting to proxy $proxy_host:$proxy_port...\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
206 0 $socket = IO::Socket::INET->new(
207 PeerAddr => $proxy_host,
208 PeerPort => $proxy_port,
209 Proto => 'tcp',
210 Timeout => $timeout,
211 );
212 0 ▶ unless ($socket) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($socket) 0 0 0
213 0 push(@errors, "- ERROR: Cannot connect to proxy: $!\n");
214 0 return (0, \@errors, \@debug, ECONNECT);
215 }
216  
217 0 my $connect_req = "CONNECT $target_host:$target_port HTTP/1.1\r\n";
218 0 $connect_req .= "Host: $target_host:$target_port\r\n";
219 0 ▶ if ($proxy_auth) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy_auth) 0 0 0
220 0 my $encoded = encode_base64($proxy_auth, '');
221 0 $connect_req .= "Proxy-Authorization: Basic $encoded\r\n";
222 0 ▶ push(@debug, "- Proxy-Authorization: " . _sanitize_credentials("Basic $encoded") . "\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
223 }
224 0 $connect_req .= "\r\n";
225 0 print $socket $connect_req;
226  
227 0 my $proxy_resp = _read_line_from_socket($self, $socket, $timeout, \$self->{_buffer});
228 0 ▶ unless ($proxy_resp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($proxy_resp) 0 0 0
229 0 push(@errors, "- ERROR: Failed to read proxy response: $!\n");
230 0 ▶ $socket->close() if $socket;
Branch: 1 branch
BranchTrueFalseTotal
if $socket 0 0 0
231 0 return (0, \@errors, \@debug, ECONNECT);
232 }
233  
234 0 ▶ unless ($proxy_resp =~ /^HTTP\/1\.[01]\s+200\b/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($proxy_resp =~ m[^HTTP/1\.[01]\s+200\b]i) 0 0 0
235 0 ▶ $socket->close() if $socket;
Branch: 1 branch
BranchTrueFalseTotal
if $socket 0 0 0
236 0 push(@errors, "- ERROR: Proxy CONNECT failed:\n$proxy_resp");
237 0 return (0, \@errors, \@debug, ECONNECT);
238 }
239 0 ▶ push(@debug, "- Proxy tunnel established.\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
240  
241 0 ▶ if (IO::Socket::SSL->start_SSL($socket, %ssl_opts)) {
Branch: 1 branch
BranchTrueFalseTotal
if ('IO::Socket::SSL'->start_SSL($socket, %ssl_opts)) { } 0 0 0
242 0 $socket->timeout($timeout);
243 0 ▶ push(@debug, "- SSL connect established.\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
244 0 $self->{_socket} = $socket;
245 0 $self->{_connected} = 1;
246 0 return (1, \@errors, \@debug, 0);
247 } else {
248 0 push(@errors, "- ERROR: SSL connect failed: $SSL_ERROR\n");
249 0 return (0, \@errors, \@debug, ESSL);
250 }
251 } else {
252 0 ▶ push(@debug, "# Connecting to $target_host:$target_port...\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
253 0 $socket = IO::Socket::SSL->new(
254 PeerHost => $target_host,
255 PeerPort => $target_port,
256 %ssl_opts,
257 );
258 0 ▶ if ($socket) {
Branch: 1 branch
BranchTrueFalseTotal
if ($socket) { } 0 0 0
259 0 $socket->timeout($timeout);
260 0 ▶ push(@debug, "- Direct SSL connect established.\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
261 0 $self->{_socket} = $socket;
262 0 $self->{_connected} = 1;
263 0 return (1, \@errors, \@debug, 0);
264 } else {
265 0 push(@errors, "- ERROR: Direct SSL connection failed: $SSL_ERROR\n");
266 0 return (0, \@errors, \@debug, ESSL);
267 }
268 }
269 }
270  
271 0 ▶sub reconnect {
Subroutine reconnect: not called CC=3 SCAR=24.8
Pod documented
272 0 my ($self) = @_;
273 0 ▶ return 0 unless $self->{_target_host} && $self->{_target_port};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_target_host"} and $self->{"_target_port"} 0 0 0
Condition0%0/3
$self->{"_target_host"} and $self->{"_target_port"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_target_host"} and $self->{"_target_port"}
$self->{"_target_host"} $self->{"_target_port"}
Truth table0%0/3
A and B
A= $self->{"_target_host"}B= $self->{"_target_port"}
ABresult
0X0
100
111
274 0 $self->close();
275 my ($ok, $err, $dbg, $code) = $self->connect(
276 $self->{_target_host},
277 $self->{_target_port},
278 $self->{_proxy},
279 $self->{_proxy_auth},
280 0 );
281 0 return $ok;
282 }
283  
284 3 ▶sub request {
Subroutine request: called CC=31 SCAR=65.7
Pod documented
285 3 my ($self, $method, $path, %opts) = @_;
286  
287 3 my $socket = $self->{_socket};
288 3 my @debug;
289 my @errors;
290  
291 3 ▶ push(@debug, "# === LightTCP::SSLclient::request ===\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 1 2 3
292 3 ▶ push(@debug, "- Sending: $method $path HTTP/1.1\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 1 2 3
293  
294 3 ▶ unless ($socket) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($socket) 3 0 3
295 3 push(@errors, "- ERROR: No connection established\n");
296 3 return (0, \@errors, \@debug, EREQUEST);
297 }
298  
299 0 ▶ my $host = $opts{host} // '';
Condition0%0/2
$opts{"host"} // ""
l!l
00
MC/DC0%0/1
$opts{"host"} // ""
$opts{"host"}
Truth table0%0/2
A
A= $opts{"host"}
Aresult
11
00
300 0 ▶ my $payload = $opts{payload} // '';
Condition0%0/2
$opts{"payload"} // ""
l!l
00
MC/DC0%0/1
$opts{"payload"} // ""
$opts{"payload"}
Truth table0%0/2
A
A= $opts{"payload"}
Aresult
11
00
301 0 ▶ my $ph = $opts{headers} // {};
Condition0%0/2
$opts{"headers"} // {}
l!l
00
MC/DC0%0/1
$opts{"headers"} // {}
$opts{"headers"}
Truth table0%0/2
A
A= $opts{"headers"}
Aresult
11
00
302  
303 0 ▶ my $length = defined $payload ? length($payload) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $payload ? : 0 0 0
304  
305 0 ▶ $ph->{'Host'} ||= $host;
Condition0%0/3
$ph->{"Host"} ||= $host
l!l&&r!l&&!r
000
MC/DC0%0/2
$ph->{"Host"} ||= $host
$ph->{"Host"} $host
Truth table0%0/3
A ||= B
A= $ph->{"Host"}B= $host
ABresult
1X1
011
000
306 0 ▶ $ph->{'Accept'} ||= '*/*';
Condition0%0/2
$ph->{"Accept"} ||= "*/*"
l!l
00
MC/DC0%0/1
$ph->{"Accept"} ||= "*/*"
$ph->{"Accept"}
Truth table0%0/2
A
A= $ph->{"Accept"}
Aresult
11
00
307 0 ▶ $ph->{'User-Agent'} ||= $self->{user_agent};
Condition0%0/3
$ph->{"User-Agent"} ||= $self->{"user_agent"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ph->{"User-Agent"} ||= $self->{"user_agent"}
$ph->{"User-Agent"} $self->{"user_agent"}
Truth table0%0/3
A ||= B
A= $ph->{"User-Agent"}B= $self->{"user_agent"}
ABresult
1X1
011
000
308 0 ▶ $ph->{'Connection'} ||= $self->{keep_alive} ? 'keep-alive' : 'close';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'keep_alive'} ? : 0 0 0
Condition0%0/3
$ph->{"Connection"} ||= $self->{"keep_alive"} ? "keep-alive" : "close"
l!l&&r!l&&!r
000
MC/DC0%0/2
$ph->{"Connection"} ||= $self->{"keep_alive"} ? "keep-alive" : "close"
$ph->{"Connection"} $self->{"keep_alive"} ? "keep-alive" : "close"
Truth table0%0/3
A ||= B
A= $ph->{"Connection"}B= $self->{"keep_alive"} ? "keep-alive" : "close"
ABresult
1X1
011
000
309  
310 0 my $timeout = $self->{timeout};
311 0 my $send_ok = 1;
312  
313 0 eval {
314 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
315 0 alarm $timeout;
316  
317 0 ▶ unless (print $socket "$method $path HTTP/1.1\r\n") {
Branch: 1 branch
BranchTrueFalseTotal
unless (print $socket "$method $path HTTP/1.1\r\n") 0 0 0
318 0 push(@errors, "- ERROR: Failed to send request line: $!\n");
319 0 $send_ok = 0;
320 }
321  
322 0 ▶ if ($send_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($send_ok) 0 0 0
323 0 ▶ push(@debug, "# === Headers: ===\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
324 0 foreach my $key (sort keys %$ph) {
325 0 ▶ my $val = $ph->{$key} // '';
Condition0%0/2
$ph->{$key} // ""
l!l
00
MC/DC0%0/1
$ph->{$key} // ""
$ph->{$key}
Truth table0%0/2
A
A= $ph->{$key}
Aresult
11
00
326 0 $val =~ s/[\r\n]+//g;
327 0 $val =~ s/^\s+|\s+$//g;
328 0 ▶ push(@debug, "- $key: $val\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
329 0 ▶ unless (print $socket "$key: $val\r\n") {
Branch: 1 branch
BranchTrueFalseTotal
unless (print $socket "${key}: $val\r\n") 0 0 0
330 0 push(@errors, "- ERROR: Failed to send header '$key': $!\n");
331 0 $send_ok = 0;
332 0 last;
333 }
334 }
335 }
336  
337 0 ▶ if ($send_ok && $length > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($send_ok and $length > 0) 0 0 0
Condition0%0/3
$send_ok and $length > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$send_ok and $length > 0
$send_ok $length > 0
Truth table0%0/3
A and B
A= $send_okB= $length > 0
ABresult
0X0
100
111
338 0 ▶ unless (print $socket "Content-Length: $length\r\n") {
Branch: 1 branch
BranchTrueFalseTotal
unless (print $socket "Content-Length: $length\r\n") 0 0 0
339 0 push(@errors, "- ERROR: Failed to send Content-Length: $!\n");
340 0 $send_ok = 0;
341 }
342 }
343  
344 0 ▶ if ($send_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($send_ok) 0 0 0
345 0 ▶ unless (print $socket "\r\n") {
Branch: 1 branch
BranchTrueFalseTotal
unless (print $socket "\r\n") 0 0 0
346 0 push(@errors, "- ERROR: Failed to send header terminator: $!\n");
347 0 $send_ok = 0;
348 }
349 }
350  
351 0 ▶ if ($send_ok && defined $payload && $length > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($send_ok and defined $payload and $length > 0) 0 0 0
Condition0%0/6
$send_ok and defined $payload and $length > 0
!ll&&!rl&&r
000
$send_ok and defined $payload
!ll&&!rl&&r
000
MC/DC0%0/3
$send_ok and defined $payload and $length > 0
$send_ok defined $payload $length > 0
Truth table0%0/4
A and B and C
A= $send_okB= defined $payloadC= $length > 0
ABCresult
0XX0
10X0
1100
1111
352 0 ▶ unless (print $socket $payload) {
Branch: 1 branch
BranchTrueFalseTotal
unless (print $socket $payload) 0 0 0
353 0 push(@errors, "- ERROR: Failed to send payload (connection broken): $!\n");
354 0 $send_ok = 0;
355 }
356 }
357  
358 0 alarm 0;
359 };
360 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
361 0 push(@errors, "- ERROR: Timeout during request send\n");
362 0 return (0, \@errors, \@debug, ETIMEOUT);
363 }
364  
365 0 ▶ unless ($send_ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($send_ok) 0 0 0
366 0 return (0, \@errors, \@debug, EREQUEST);
367 }
368 0 return (1, \@errors, \@debug, 0);
369 }
370  
371 0 ▶sub request_with_redirects {
Subroutine request_with_redirects: not called CC=1 SCAR=6.9
Pod documented
372 0 my ($self, $method, $path, %opts) = @_;
373  
374 0 $self->{_redirect_count} = 0;
375 0 $self->{_redirect_history} = [];
376  
377 0 return $self->_do_request_with_redirects($method, $path, %opts);
378 }
379  
380 0 ▶sub _do_request_with_redirects {
Subroutine _do_request_with_redirects: not called CC=14 SCAR=53.5
381 0 my ($self, $method, $path, %opts) = @_;
382  
383 0 my @errors;
384 my @debug;
385 0 my ($ok, $req_errors, $req_debug, $error_code) = $self->request($method, $path, %opts);
386 0 ▶ push(@errors, @$req_errors) if $req_errors;
Branch: 1 branch
BranchTrueFalseTotal
if $req_errors 0 0 0
387 0 ▶ push(@debug, @$req_debug) if $req_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $req_debug 0 0 0
388 0 ▶ return (undef, undef, undef, undef, \@errors, \@debug, $error_code, []) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
389  
390 0 my ($code, $state, $headers, $body, $resp_errors, $resp_debug, $resp_code) = $self->response();
391 0 ▶ push(@errors, @$resp_errors) if $resp_errors;
Branch: 1 branch
BranchTrueFalseTotal
if $resp_errors 0 0 0
392 0 ▶ push(@debug, @$resp_debug) if $resp_debug;
Branch: 1 branch
BranchTrueFalseTotal
if $resp_debug 0 0 0
393 0 ▶ return ($code, $state, $headers, $body, \@errors, \@debug, $resp_code, $self->{_redirect_history}) unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
394  
395 0 ▶ if ($self->{follow_redirects} && $code >= 300 && $code < 400 && $headers && $headers->{'location'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"follow_redirects"} and $code >= 300 and $code < 400 and $headers and $headers->{"location"}) 0 0 0
Condition0%0/12
$self->{"follow_redirects"} and $code >= 300 and $code < 400 and $headers and $headers->{"location"}
!ll&&!rl&&r
000
$self->{"follow_redirects"} and $code >= 300 and $code < 400 and $headers
!ll&&!rl&&r
000
$self->{"follow_redirects"} and $code >= 300 and $code < 400
!ll&&!rl&&r
000
$self->{"follow_redirects"} and $code >= 300
!ll&&!rl&&r
000
MC/DC0%0/5
$self->{"follow_redirects"} and $code >= 300 and $code < 400 and $headers and $headers->{"location"}
$self->{"follow_redirects"} $code >= 300 $code < 400 $headers $headers->{"location"}
Truth table0%0/6
A and B and C and D and E
A= $self->{"follow_redirects"}B= $code >= 300C= $code < 400D= $headersE= $headers->{"location"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
396 0 ▶ return ($code, $state, $headers, $body, $resp_errors, $resp_debug, $resp_code, $self->{_redirect_history}) if $self->{_redirect_count} >= $self->{max_redirects};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_redirect_count"} >= $self->{"max_redirects"} 0 0 0
397  
398 0 my $location = $headers->{'location'};
399  
400 0 push(@{$self->{_redirect_history}}, {
401 from => "$method $path",
402 to => $location,
403 code => $code,
404 });
405  
406 0 $self->{_redirect_count}++;
407  
408 0 my ($new_method, $new_path, $new_host, $new_opts) = $self->_resolve_redirect($method, $path, $location, %opts);
409  
410 0 my $debug_msg = "- Following redirect ($code): $method $path -> $new_method $new_path\n";
411 0 ▶ push(@$resp_debug, $debug_msg) if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
412  
413 0 return $self->_do_request_with_redirects($new_method, $new_path, %$new_opts);
414 }
415  
416 0 return ($code, $state, $headers, $body, $resp_errors, $resp_debug, $resp_code, $self->{_redirect_history});
417 }
418  
419 0 ▶sub _resolve_redirect {
Subroutine _resolve_redirect: not called CC=13 SCAR=52.0
420 0 my ($self, $method, $path, $location, %opts) = @_;
421  
422 0 my $uri = URI->new($location);
423 0 my $new_method = $method;
424 0 ▶ my $new_path = $uri->path_query || '/';
Condition0%0/2
$uri->path_query || '/'
l!l
00
MC/DC0%0/1
$uri->path_query || '/'
$uri->path_query
Truth table0%0/2
A
A= $uri->path_query
Aresult
11
00
425 0 ▶ my $new_host = $opts{host} // '';
Condition0%0/2
$opts{"host"} // ""
l!l
00
MC/DC0%0/1
$opts{"host"} // ""
$opts{"host"}
Truth table0%0/2
A
A= $opts{"host"}
Aresult
11
00
426  
427 0 ▶ if ($uri->scheme) {
Branch: 2 branches
BranchTrueFalseTotal
if ($uri->scheme) { } 0 0 0
elsif ($location =~ m[^/]) { } 0 0 0
428 0 ▶ if ($uri->scheme ne 'https') {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri->scheme ne "https") 0 0 0
429 0 return ($method, $path, '', \%opts);
430 }
431 0 $new_host = $uri->host;
432 0 ▶ $new_path = $uri->path_query || '/';
Condition0%0/2
$uri->path_query || '/'
l!l
00
MC/DC0%0/1
$uri->path_query || '/'
$uri->path_query
Truth table0%0/2
A
A= $uri->path_query
Aresult
11
00
433 0 ▶ if ($uri->port && $uri->port != 443) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri->port and $uri->port != 443) 0 0 0
Condition0%0/3
$uri->port and $uri->port != 443
!ll&&!rl&&r
000
MC/DC0%0/2
$uri->port and $uri->port != 443
$uri->port $uri->port != 443
Truth table0%0/3
A and B
A= $uri->portB= $uri->port != 443
ABresult
0X0
100
111
434 0 $new_host = $uri->host . ':' . $uri->port;
435 }
436 } elsif ($location =~ m{^/}) {
437 0 $new_path = $location;
438 } else {
439 0 $new_path = $self->_resolve_relative_path($path, $location);
440 }
441  
442 0 my %new_opts = %opts;
443 0 $new_opts{host} = $new_host;
444  
445 0 ▶ if ($location =~ /^HTTP\/1\.[01] (30[1278])\b/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($location =~ m[^HTTP/1\.[01] (30[1278])\b]i) 0 0 0
446 0 my $code = $1;
447 0 ▶ if ($code eq '301' || $code eq '302') {
Branch: 1 branch
BranchTrueFalseTotal
if ($code eq 301 or $code eq 302) 0 0 0
Condition0%0/3
$code eq 301 or $code eq 302
l!l&&r!l&&!r
000
MC/DC0%0/2
$code eq 301 or $code eq 302
$code eq 301 $code eq 302
Truth table0%0/3
A or B
A= $code eq 301B= $code eq 302
ABresult
1X1
011
000
448 0 ▶ if ($method eq 'POST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "POST") 0 0 0
449 0 $new_method = 'GET';
450 0 $new_opts{payload} = undef;
451 }
452 }
453 }
454  
455 0 return ($new_method, $new_path, $new_host, \%new_opts);
456 }
457  
458 3 ▶sub _resolve_relative_path {
Subroutine _resolve_relative_path: called CC=4 SCAR=14.1
459 3 my ($self, $current_path, $relative) = @_;
460  
461 3 ▶ return $relative if $relative =~ m{^/};
Branch: 1 branch
BranchTrueFalseTotal
if $relative =~ m[^/] 0 3 3
462  
463 3 $current_path =~ s{/[^/]*$}{};
464 3 ▶ $current_path = '/' unless length $current_path;
Branch: 1 branch
BranchTrueFalseTotal
unless length $current_path 0 3 3
465  
466 3 my $result = $current_path;
467 3 ▶ $result .= '/' unless $result =~ m{/$};
Branch: 1 branch
BranchTrueFalseTotal
unless $result =~ m[/$] 3 0 3
468 3 $result .= $relative;
469  
470 3 $result =~ s{[^/]+/\.\./}{}g;
471 3 $result =~ s{/\./}{}g;
472 3 $result =~ s{//+}{/};
473  
474 3 return $result;
475 }
476  
477 3 ▶sub response {
Subroutine response: called CC=19 SCAR=55.7
Pod documented
478 3 my ($self) = @_;
479  
480 3 my $socket = $self->{_socket};
481 3 my @resp_debug;
482 my @resp_errors;
483  
484 3 ▶ push(@resp_debug, "# === LightTCP::SSLclient::response ===\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 1 2 3
485  
486 3 ▶ unless ($socket) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($socket) 3 0 3
487 3 push(@resp_errors, "- ERROR: No connection established\n");
488 3 return (undef, undef, undef, undef, \@resp_errors, \@resp_debug, ERESPONSE);
489 }
490  
491 0 ▶ my $timeout = $socket->timeout // 15;
Condition0%0/2
$socket->timeout // 15
l!l
00
MC/DC0%0/1
$socket->timeout // 15
$socket->timeout
Truth table0%0/2
A
A= $socket->timeout
Aresult
11
00
492  
493 0 my $headers_raw = '';
494 0 my $buf;
495 0 my $buf_size = $self->{buffer_size};
496 0 eval {
497 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
498 0 alarm $timeout;
499 0 ▶ while (sysread($socket, $buf, $buf_size)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread $socket, $buf, $buf_size) 0 0 0
500 0 $headers_raw .= $buf;
501 0 ▶ last if $headers_raw =~ /\r\n\r\n|\n\n/;
Branch: 1 branch
BranchTrueFalseTotal
if $headers_raw =~ /\r\n\r\n|\n\n/ 0 0 0
502 }
503 0 alarm 0
504 };
505 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
506 0 push(@resp_errors, "- ERROR: Timeout while reading response headers\n");
507 0 return (undef, undef, undef, undef, \@resp_errors, \@resp_debug, ETIMEOUT);
508 }
509  
510 0 ▶ unless ($headers_raw =~ /^HTTP\/1\.[01]\s+(\d{3})\s+(.*?)\r?\n/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($headers_raw =~ m[^HTTP/1\.[01]\s+(\d{3})\s+(.*?)\r?\n]i) 0 0 0
511 0 push(@resp_errors, "- ERROR: INVALID RESPONSE (no valid status line)\n");
512 0 return (undef, undef, undef, undef, \@resp_errors, \@resp_debug, ERESPONSE);
513 }
514 0 my $code = $1;
515 0 my $state = $2;
516 0 ▶ push(@resp_debug, "- $code $state\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
517  
518 0 ▶ my ($headers_part, $initial_body) = $headers_raw =~ /^(.*?)\r\n\r\n(.*)$/s
Branch: 1 branch
BranchTrueFalseTotal
$headers_raw =~ /^(.*?)\r\n\r\n(.*)$/s ? : 0 0 0
519 ? ($1, $2)
520 : ($headers_raw, '');
521  
522 0 my @lines = split /\r?\n/, $headers_part;
523 0 shift @lines;
524  
525 0 my %hdr;
526 0 my $current_key = '';
527 0 for my $line (@lines) {
528 0 ▶ if ($line =~ /^\s+(.+)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^\s+(.+)/) { } 0 0 0
elsif ($line =~ /^([^:]+):\s*(.*)/) { } 0 0 0
529 0 ▶ $hdr{$current_key} .= " $1" if $current_key;
Branch: 1 branch
BranchTrueFalseTotal
if $current_key 0 0 0
530 } elsif ($line =~ /^([^:]+):\s*(.*)/) {
531 0 $current_key = lc $1;
532 0 $hdr{$current_key} = $2;
533 }
534 }
535  
536 0 my $body = $initial_body;
537 0 ▶ my $chunked = (lc($hdr{'transfer-encoding'} || '') eq 'chunked');
Condition0%0/2
$hdr{'transfer-encoding'} || ''
l!l
00
MC/DC0%0/1
$hdr{'transfer-encoding'} || ''
$hdr{'transfer-encoding'}
Truth table0%0/2
A
A= $hdr{'transfer-encoding'}
Aresult
11
00
538 0 ▶ my $content_length = $hdr{'content-length'} ? int($hdr{'content-length'}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$hdr{'content-length'} ? : 0 0 0
539  
540 0 ▶ if ($chunked) {
Branch: 2 branches
BranchTrueFalseTotal
if ($chunked) { } 0 0 0
elsif (defined $content_length and $content_length > length $body) { } 0 0 0
541 0 $body = $self->_read_chunked_with_timeout($body, $timeout, \@resp_errors, \@resp_debug);
542 ▶ } elsif (defined $content_length && $content_length > length($body)) {
Condition0%0/3
defined $content_length and $content_length > length $body
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content_length and $content_length > length $body
defined $content_length $content_length > length $body
Truth table0%0/3
A and B
A= defined $content_lengthB= $content_length > length $body
ABresult
0X0
100
111
543 0 $body = $self->_read_exact_bytes_with_timeout($body, $content_length - length($body), $timeout, \@resp_errors, \@resp_debug);
544 } else {
545 0 $body = $self->_read_until_eof_with_timeout($body, $timeout, \@resp_errors, \@resp_debug);
546 }
547  
548 0 return ($code, $state, \%hdr, $body, \@resp_errors, \@resp_debug, 0);
549 }
550  
551 0 ▶sub _read_exact_bytes_with_timeout {
Subroutine _read_exact_bytes_with_timeout: not called CC=6 SCAR=37.4
552 0 my ($self, $initial, $remaining, $timeout, $perrs, $pdebug) = @_;
553 0 my $body = $initial;
554 0 my $buf;
555 0 my $socket = $self->{_socket};
556 0 my $buf_size = $self->{buffer_size};
557  
558 0 eval {
559 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
560 0 alarm $timeout;
561 0 ▶ while ($remaining > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining > 0) 0 0 0
562 0 ▶ my $read = sysread($socket, $buf, ($remaining > $buf_size ? $buf_size : $remaining));
Branch: 1 branch
BranchTrueFalseTotal
$remaining > $buf_size ? : 0 0 0
563 0 ▶ last unless defined $read && $read > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $read and $read > 0 0 0 0
Condition0%0/3
defined $read and $read > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $read and $read > 0
defined $read $read > 0
Truth table0%0/3
A and B
A= defined $readB= $read > 0
ABresult
0X0
100
111
564 0 $body .= $buf;
565 0 $remaining -= $read;
566 }
567 0 alarm 0
568 };
569 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
570 0 push(@$perrs, "- WARNING: Timeout during Content-Length body read (incomplete body)\n");
571 }
572 0 return $body;
573 }
574  
575 0 ▶sub _read_until_eof_with_timeout {
Subroutine _read_until_eof_with_timeout: not called CC=3 SCAR=24.8
576 0 my ($self, $initial, $timeout, $perrs, $pdebug) = @_;
577 0 my $body = $initial;
578 0 my $buf;
579 0 my $socket = $self->{_socket};
580 0 my $buf_size = $self->{buffer_size};
581  
582 0 eval {
583 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
584 0 alarm $timeout;
585 0 ▶ while (sysread($socket, $buf, $buf_size)) {
Branch: 1 branch
BranchTrueFalseTotal
if (sysread $socket, $buf, $buf_size) 0 0 0
586 0 $body .= $buf;
587 }
588 0 alarm 0
589 };
590 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
591 0 push(@$perrs, "- WARNING: Timeout during EOF body read (connection may have stalled)\n");
592 }
593 0 return $body;
594 }
595  
596 0 ▶sub _read_chunked_with_timeout {
Subroutine _read_chunked_with_timeout: not called CC=12 SCAR=50.5
597 0 my ($self, $initial, $timeout, $perrs, $pdebug) = @_;
598 0 my $body = $initial;
599 0 my $buf;
600 0 my $socket = $self->{_socket};
601 0 my $buffer = $self->{_buffer};
602 0 my $buf_size = $self->{buffer_size};
603  
604 0 eval {
605 0 ▶ local $SIG{ALRM} = sub { die "timeout\n" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
606 0 alarm $timeout;
607  
608 0 while (1) {
609 0 my $chunk_line = _read_until_delimiter($self, $socket, $buffer, $timeout, "\n");
610 0 ▶ last unless defined $chunk_line && length($chunk_line);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunk_line and length $chunk_line 0 0 0
Condition0%0/3
defined $chunk_line and length $chunk_line
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chunk_line and length $chunk_line
defined $chunk_line length $chunk_line
Truth table0%0/3
A and B
A= defined $chunk_lineB= length $chunk_line
ABresult
0X0
100
111
611  
612 0 $chunk_line =~ s/\r?\n$//;
613 0 my $chunk_size = hex($chunk_line);
614 0 ▶ push(@$pdebug, "- Chunk size: $chunk_size\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 0 0
615  
616 0 ▶ last if $chunk_size == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $chunk_size == 0 0 0 0
617  
618 0 my $read_so_far = 0;
619 0 ▶ while ($read_so_far < $chunk_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read_so_far < $chunk_size) 0 0 0
620 0 my $need = $chunk_size - $read_so_far;
621 0 ▶ my $read = sysread($socket, $buf, ($need > $buf_size ? $buf_size : $need));
Branch: 1 branch
BranchTrueFalseTotal
$need > $buf_size ? : 0 0 0
622 0 ▶ unless (defined $read && $read > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $read and $read > 0) 0 0 0
Condition0%0/3
defined $read and $read > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $read and $read > 0
defined $read $read > 0
Truth table0%0/3
A and B
A= defined $readB= $read > 0
ABresult
0X0
100
111
623 0 push(@$perrs, "- WARNING: Failed to read chunk data\n");
624 0 last;
625 }
626 0 $body .= $buf;
627 0 $read_so_far += $read;
628 }
629  
630 0 my $trailing = _read_exact_bytes($socket, 2, $timeout);
631 0 ▶ unless ($trailing eq "\r\n" || $trailing eq "\n") {
Branch: 1 branch
BranchTrueFalseTotal
unless ($trailing eq "\r\n" or $trailing eq "\n") 0 0 0
Condition0%0/3
$trailing eq "\r\n" or $trailing eq "\n"
l!l&&r!l&&!r
000
MC/DC0%0/2
$trailing eq "\r\n" or $trailing eq "\n"
$trailing eq "\r\n" $trailing eq "\n"
Truth table0%0/3
A or B
A= $trailing eq "\r\n"B= $trailing eq "\n"
ABresult
1X1
011
000
632 0 push(@$perrs, "- WARNING: Invalid chunk trailer, expected CRLF, got: " . _hex_dump($trailing) . "\n");
633 }
634 }
635 0 alarm 0
636 };
637 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
638 0 push(@$perrs, "- WARNING: Timeout during chunked transfer (incomplete body)\n");
639 }
640 0 $self->{_buffer} = $buffer;
641 0 return $body;
642 }
643  
644 5 ▶sub fingerprint_read {
Subroutine fingerprint_read: called CC=6 SCAR=18.5
Pod documented
645 5 my ($self, $dir, $host, $port) = @_;
646 5 my $file = "$dir/$host.$port";
647 5 ▶ return '' unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 2 3 5
648  
649 3 ▶ open my $fh, '<', $file or return '';
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or return "" 3 0 3
650 3 my $fp = <$fh>;
651 3 close $fh;
652 3 ▶ chomp $fp if defined $fp;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fp 3 0 3
653 3 ▶ $fp =~ s/^\s+|\s+$//g if defined $fp;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fp 3 0 3
654 3 ▶ return $fp // '';
Condition50%1/2
$fp // ""
l!l
30
MC/DC0%0/1
$fp // ""
$fp
Truth table50%1/2
A
A= $fp
Aresult
11
00
655 }
656  
657 8 ▶sub fingerprint_save {
Subroutine fingerprint_save: called CC=7 SCAR=19.5
Pod documented
658 8 my ($self, $dir, $host, $port, $fingerprint, $save) = @_;
659 8 ▶ my $suffix = $save ? '' : '.new';
Branch: 1 branch
BranchTrueFalseTotal
$save ? : 4 4 8
660 8 my $file = "$dir/$host.$port$suffix";
661 8 my @errors;
662 my @debug;
663 8 ▶ mkdir $dir unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 2 6 8
664 8 ▶ open my $fh, '>', $file or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $file or do { push @errors, qq[- WARNING: Cannot save fingerprint to "$file": $!\n]; return 1, \@errors, \@debug, 2 } 6 2 8
665 2 push(@errors, "- WARNING: Cannot save fingerprint to \"$file\": $!\n");
666 2 return (1, \@errors, \@debug, EREQUEST);
667 };
668 6 print $fh "$fingerprint\n";
669 6 close $fh;
670 6 ▶ push(@debug, "- Saved fingerprint to: $file\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 2 4 6
671 6 ▶ if ($save) {
Branch: 1 branch
BranchTrueFalseTotal
if ($save) 2 4 6
672 2 ▶ unlink("$file.new") if -f "$file.new";
Branch: 1 branch
BranchTrueFalseTotal
if -f "$file.new" 0 2 2
673 2 return (1, \@errors, \@debug, 0);
674 }
675 4 return (1, \@errors, \@debug, 0);
676 }
677  
678 31 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
679 31 my ($self) = @_;
680 31 ▶ $self->close() if $self->{_connected};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_connected"} 1 30 31
681 }
682  
683 1 ▶sub socket {
Subroutine socket: called CC=1 SCAR=0.0
Pod documented
684 1 my ($self) = @_;
685 1 return $self->{_socket};
686 }
687  
688 4 ▶sub is_connected {
Subroutine is_connected: called CC=1 SCAR=0.0
Pod documented
689 4 my ($self) = @_;
690 4 return $self->{_connected};
691 }
692  
693 3 ▶sub close {
Subroutine close: called CC=2 SCAR=8.5
Pod documented
694 3 my ($self) = @_;
695 3 ▶ if ($self->{_socket}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_socket"}) 0 3 3
696 0 $self->{_socket}->close();
697 0 $self->{_socket} = undef;
698 0 $self->{_connected} = 0;
699 }
700 3 $self->{_buffer} = '';
701 3 return 1;
702 }
703  
704 1 ▶sub set_cert {
Subroutine set_cert: called CC=1 SCAR=0.0
Pod documented
705 1 my ($self, $cert) = @_;
706 1 $self->{cert} = $cert;
707 1 return $self->{cert};
708 }
709  
710 1 ▶sub set_timeout {
Subroutine set_timeout: called CC=3 SCAR=11.4
Pod documented
711 1 my ($self, $timeout) = @_;
712 1 ▶ $self->{timeout} = $timeout // 10;
Condition50%1/2
$timeout // 10
l!l
10
MC/DC0%0/1
$timeout // 10
$timeout
Truth table50%1/2
A
A= $timeout
Aresult
11
00
713 1 ▶ $self->{_socket}->timeout($self->{timeout}) if $self->{_socket};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_socket"} 0 1 1
714 1 return $self->{timeout};
715 }
716  
717 2 ▶sub set_insecure {
Subroutine set_insecure: called CC=2 SCAR=6.9
Pod documented
718 2 my ($self, $insecure) = @_;
719 2 ▶ $self->{insecure} = $insecure ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$insecure ? : 1 1 2
720 2 return $self->{insecure};
721 }
722  
723 2 ▶sub set_keep_alive {
Subroutine set_keep_alive: called CC=2 SCAR=7.1
Pod documented
724 2 my ($self, $keep_alive) = @_;
725 2 ▶ $self->{keep_alive} = $keep_alive ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$keep_alive ? : 2 0 2
726 2 return $self->{keep_alive};
727 }
728  
729 4 ▶sub get_timeout {
Subroutine get_timeout: called CC=1 SCAR=0.0
Pod documented
730 4 my ($self) = @_;
731 4 return $self->{timeout};
732 }
733  
734 2 ▶sub get_user_agent {
Subroutine get_user_agent: called CC=1 SCAR=0.0
Pod documented
735 2 my ($self) = @_;
736 2 return $self->{user_agent};
737 }
738  
739 3 ▶sub is_verbose {
Subroutine is_verbose: called CC=1 SCAR=0.0
Pod undocumented
740 3 my ($self) = @_;
741 3 return $self->{verbose};
742 }
743  
744 1 ▶sub get_cert {
Subroutine get_cert: called CC=1 SCAR=0.0
Pod documented
745 1 my ($self) = @_;
746 1 return $self->{cert};
747 }
748  
749 1 ▶sub get_insecure {
Subroutine get_insecure: called CC=1 SCAR=0.0
Pod documented
750 1 my ($self) = @_;
751 1 return $self->{insecure};
752 }
753  
754 1 ▶sub get_ssl_protocols {
Subroutine get_ssl_protocols: called CC=1 SCAR=0.0
Pod documented
755 1 my ($self) = @_;
756 1 return $self->{ssl_protocols};
757 }
758  
759 1 ▶sub get_ssl_ciphers {
Subroutine get_ssl_ciphers: called CC=1 SCAR=0.0
Pod documented
760 1 my ($self) = @_;
761 1 return $self->{ssl_ciphers};
762 }
763  
764 7 ▶sub get_keep_alive {
Subroutine get_keep_alive: called CC=1 SCAR=0.0
Pod documented
765 7 my ($self) = @_;
766 7 return $self->{keep_alive};
767 }
768  
769 1 ▶sub is_keep_alive {
Subroutine is_keep_alive: called CC=1 SCAR=0.0
Pod undocumented
770 1 my ($self) = @_;
771 1 return $self->{keep_alive};
772 }
773  
774 7 ▶sub get_buffer_size {
Subroutine get_buffer_size: called CC=1 SCAR=0.0
Pod documented
775 7 my ($self) = @_;
776 7 return $self->{buffer_size};
777 }
778  
779 2 ▶sub set_buffer_size {
Subroutine set_buffer_size: called CC=3 SCAR=11.0
Pod undocumented
780 2 my ($self, $size) = @_;
781 2 ▶ $self->{buffer_size} = defined $size && $size > 0 ? $size : 8192;
Branch: 1 branch
BranchTrueFalseTotal
defined $size && $size > 0 ? : 1 1 2
Condition66%2/3
defined $size and $size > 0
!ll&&!rl&&r
011
MC/DC50%1/2
defined $size and $size > 0
defined $size $size > 0
Truth table66%2/3
A and B
A= defined $sizeB= $size > 0
ABresult
0X0
100
111
782 2 return $self->{buffer_size};
783 }
784  
785 4 ▶sub get_max_redirects {
Subroutine get_max_redirects: called CC=1 SCAR=0.0
Pod documented
786 4 my ($self) = @_;
787 4 return $self->{max_redirects};
788 }
789  
790 5 ▶sub get_follow_redirects {
Subroutine get_follow_redirects: called CC=1 SCAR=0.0
Pod documented
791 5 my ($self) = @_;
792 5 return $self->{follow_redirects};
793 }
794  
795 1 ▶sub set_max_redirects {
Subroutine set_max_redirects: called CC=2 SCAR=7.1
Pod documented
796 1 my ($self, $max) = @_;
797 1 ▶ $self->{max_redirects} = $max // 5;
Condition50%1/2
$max // 5
l!l
10
MC/DC0%0/1
$max // 5
$max
Truth table50%1/2
A
A= $max
Aresult
11
00
798 1 return $self->{max_redirects};
799 }
800  
801 1 ▶sub set_follow_redirects {
Subroutine set_follow_redirects: called CC=2 SCAR=7.1
Pod documented
802 1 my ($self, $follow) = @_;
803 1 ▶ $self->{follow_redirects} = $follow ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$follow ? : 0 1 1
804 1 return $self->{follow_redirects};
805 }
806  
807 1 ▶sub get_redirect_count {
Subroutine get_redirect_count: called CC=1 SCAR=0.0
Pod documented
808 1 my ($self) = @_;
809 1 return $self->{_redirect_count};
810 }
811  
812 1 ▶sub get_redirect_history {
Subroutine get_redirect_history: called CC=1 SCAR=0.0
Pod documented
813 1 my ($self) = @_;
814 1 return $self->{_redirect_history};
815 }
816  
817 6 1;
818  
819 __END__
↑ Summary script/ssltest.pl »