Branch Coverage

blib/lib/HTTP/Tiny.pm
Criterion Covered Total %
branch 337 484 69.6


line true false branch
97 0 1 if not $persist_ok{$accessor} and $_[1] ne $_[0]{$accessor}
100 1 76 if (@_ > 1) { }
107 173 6 if (@_ > 1)
109 2 171 defined $agent && $agent =~ / $/ ? :
116 3 5 if (@_ > 1)
118 2 1 if ($self->{'handle'})
130 7 165 if (exists $args{'verify_ssl'})
141 2 170 defined $args{'timeout'} ? :
27 145 defined $args{'verify_SSL'} ? :
145 9 163 if $args{'cookie_jar'}
148 143 1897 if exists $args{$key}
151 2 168 exists $args{'agent'} ? :
162 9 306 ($ENV{'PERL_HTTP_TINY_SSL_INSECURE_BY_DEFAULT'} || '') eq '1' ? :
172 167 3 unless (exists $self->{'proxy'})
176 4 166 if (defined $self->{'proxy'}) { }
184 169 1 unless (exists $self->{'http_proxy'})
186 2 167 if $ENV{'REQUEST_METHOD'}
190 10 160 if (defined $self->{'http_proxy'}) { }
199 168 1 unless (exists $self->{'https_proxy'})
203 6 163 if ($self->{'https_proxy'}) { }
212 166 3 unless (ref $self->{'no_proxy'} eq "ARRAY")
214 6 160 defined $self->{'no_proxy'} ? :
237 0 0 unless @_ == 2 or @_ == 3 and ref $args eq "HASH"
3 6 unless @_ == 2 or @_ == 3 and ref $args eq "HASH"
0 0 unless @_ == 2 or @_ == 3 and ref $args eq "HASH"
0 0 unless @_ == 2 or @_ == 3 and ref $args eq "HASH"
0 2 unless @_ == 2 or @_ == 3 and ref $args eq "HASH"
0 8 unless @_ == 2 or @_ == 3 and ref $args eq "HASH"
269 0 1 unless @_ == 3 or @_ == 4 and ref $args eq "HASH"
273 6 2 unless $args->{'headers'}
315 4 1 unless @_ == 3 or @_ == 4 and ref $args eq "HASH"
318 1 4 if (exists $args->{'headers'})
320 0 2 unless $args->{'headers'}
326 3 2 if (-e $file and my $mtime = (stat $file)[9])
332 0 5 unless sysopen my $fh, $tempfile, 193
337 0 5 unless close $fh
340 3 2 if ($response->{'success'})
341 0 3 unless rename $tempfile, $file
344 3 0 if ($lm and my $mtime = $self->_parse_http_date($lm))
464 4 114 unless @_ == 3 or @_ == 4 and ref $args eq "HASH"
472 20 0 unless $@ and $idempotent{$method} and $@ =~ /^(?:Socket closed|Unexpected end|SSL read error)/
476 20 125 if (my $e = $@)
478 0 0 if (ref $e eq "HASH" and exists $e->{'status'})
479 0 0 unless $args->{'_redirects'}
0 0 if @{[] unless $args->{'_redirects'};}
495 19 1 unless $args->{'_redirects'}
0 20 @{[] unless $args->{'_redirects'};} ? :
517 0 7 unless @_ == 2 and ref $data
519 0 7 unless ref $data eq "HASH" or ref $data eq "ARRAY"
524 3 4 ref $data eq 'HASH' ? :
526 0 7 unless @params % 2 == 0
532 1 20 unless defined $key
534 2 18 if (ref $value eq 'ARRAY') { }
569 36 0 if $INC[-1] eq "."
570 0 36 unless (eval { do { require IO::Socket::SSL; "IO::Socket::SSL"->VERSION("1.968") } })
576 0 36 unless (eval { do { require Net::SSLeay; "Net::SSLeay"->VERSION("1.49") } })
582 3 0 if (ref $self and $self->{'verify_SSL'} || $self->{'SSL_options'}{'SSL_verify_mode'})
587 1 2 unless (eval { do { $handle->_find_CA; 1 } })
593 30 6 wantarray ? :
617 0 0 if ($self->{'handle'})
636 172 0 if defined $version
645 1 157 if ($scheme ne "http" and $scheme ne "https")
654 155 2 $port == $DefaultPort{$scheme} ? :
662 0 157 if ("CODE" eq ref $peer)
670 16 141 if ($handle)
671 11 5 unless ($handle->can_reuse($scheme, $host, $port, $peer))
685 17 122 if $self->{'cookie_jar'}
689 2 137 if ($method eq 'HEAD' or $response->{'status'} =~ /^[23]04/) { }
695 13 124 @redir_args ? :
700 43 95 if ($self->{'keep_alive'} and $handle->connected and $known_message_length and $response->{'protocol'} eq 'HTTP/1.1' and ($response->{'headers'}{'connection'} || '') ne 'close') { }
717 13 125 if (@redir_args)
724 11 114 if @{$args->{'_redirects'};}
740 0 152 if $self->{'keep_alive_timeout'} > 0
742 2 150 if ($self->{'_has_proxy'}{$scheme} and not grep({$host =~ /\Q$_\E$/;} @{$$self{'no_proxy'};})) { }
754 0 2 if ($request->{'scheme'} eq 'https') { }
755 0 0 unless $self->{'https_proxy'}
757 0 0 if ($proxy_vars[0] eq "https")
762 0 2 unless $self->{'http_proxy'}
768 1 1 if (length $p_auth and not defined $request->{'headers'}{'proxy-authorization'})
774 0 2 if ($request->{'scheme'} eq 'https') { }
790 0 21 unless (defined $scheme and length $scheme and length $host and length $port and $path_query eq "/")
806 0 0 exists $request->{'headers'}{'user-agent'} ? :
817 0 0 if ($request->{'headers'}{'proxy-authorization'})
829 0 0 unless (substr($response->{'status'}, 0, 1) eq 2)
843 261 25 unless defined $_
850 1 142 if (exists $request->{'headers'}{'host'})
857 92 50 unless $self->{'keep_alive'}
860 49 93 if ($request->{'method'} eq "PUT" or $request->{'method'} eq "POST")
861 19 30 unless (defined $args->{'content'} and length $args->{'content'})
866 31 111 if (defined $args->{'content'})
867 5 26 if (ref $args->{'content'} eq 'CODE') { }
25 1 elsif (length $args->{'content'}) { }
868 0 5 if (exists $request->{'content-length'} and $request->{'content-length'} == 0) { }
875 3 0 unless exists $request->{'headers'}{'content-length'} or $request->{'headers'}{'transfer-encoding'}
881 25 0 if ("$]" >= "5.008")
882 0 25 unless utf8::downgrade($content, 1)
888 24 0 unless $request->{'headers'}{'content-length'} or $request->{'headers'}{'transfer-encoding'}
892 1 30 if ref $args->{'trailer_callback'} eq "CODE"
896 17 125 if ($self->{'cookie_jar'})
898 11 6 if length $cookies
902 4 138 if (length $auth and not defined $request->{'headers'}{'authorization'})
922 133 4 unless ($data_cb and $response->{'status'} =~ /^2/)
923 1 132 if (defined $self->{'max_size'}) { }
927 1 0 if length $_[1]{'content'} > $self->{'max_size'}
941 2 15 unless defined $cookies
943 1 14 ref $cookies ? :
955 2 15 unless ref $jar and ref($jar)->can($method)
968 13 2 if ($status eq '303' || $status =~ /^30[1278]/ && $method =~ /^GET|HEAD$/ and $headers->{'location'} and @{$args->{'_redirects'};} < $self->{'max_redirect'})
974 1 12 $headers->{'location'} =~ m[^/] ? :
975 2 11 $status eq '303' ? :
984 1 193 unless my($scheme, $host, $path_query) = $url =~ m[\A([^:/?#]+)://([^/?#]*)([^#]*)]
988 52 141 unless $path_query =~ m[\A/]
991 12 181 if ((my $i = index($host, "\@")) != -1)
999 31 2 $scheme eq 'https' ? :
139 33 $scheme eq 'http' ? :
21 172 $host =~ s/:(\d*)\z// && length $1 ? :
1004 191 2 length $host ? :
1023 5 4 if ($str =~ /^[SMTWF][a-z]+, +(\d{1,2}) ($MoY) +(\d\d\d\d) +(\d\d):(\d\d):(\d\d) +GMT$/) { }
2 2 elsif ($str =~ /^[SMTWF][a-z]+, +(\d\d)-($MoY)-(\d{2,4}) +(\d\d):(\d\d):(\d\d) +GMT$/) { }
2 0 elsif ($str =~ /^[SMTWF][a-z]+ +($MoY) +(\d{1,2}) +(\d\d):(\d\d):(\d\d) +(?:[^0-9]+ +)?(\d\d\d\d)$/) { }
1033 9 0 @tl_parts ? :
1034 0 9 $t < 0 ? :
1047 2 34 unless defined $str
1048 34 0 if ("$]" >= 5.008) { }
1053 0 0 if length $str == do { use bytes; length $str }
1106 2 0 if (@_ > 1)
1108 0 2 if ($self->{'fh'} and $self->{'fh'}->can("timeout"))
1116 0 32 unless @_ == 5
1119 29 3 if ($scheme eq "https")
1131 1 31 $self->{'local_address'} ? :
1 31 unless $self->{'fh'} = $SOCKET_CLASS->new("PeerHost", $peer, "PeerPort", $port, $self->{'local_address'} ? ("LocalAddr", $self->{'local_address'}) : (), "Proto", "tcp", "Type", 1, "Timeout", $self->{'timeout'})
1136 0 31 unless binmode $self->{'fh'}
1138 31 0 if ($self->{'keep_alive'})
1139 0 31 unless (defined $self->{'fh'}->setsockopt(1, 9, 1))
1145 29 2 if $scheme eq "https"
1159 18 0 if ($self->{'fh'} and $self->{'fh'}->connected)
1162 0 18 wantarray ? :
1173 0 29 if (ref $self->{'fh'} eq "IO::Socket::SSL")
1174 0 0 unless ($self->{'fh'}->stop_SSL)
1190 13 16 unless (ref $self->{'fh'} eq "IO::Socket::SSL")
1197 0 2 unless @_ == 1
1200 0 2 unless CORE::close $self->{'fh'}
1204 0 361 unless @_ == 2
1207 361 0 if ("$]" >= "5.008")
1208 0 361 unless utf8::downgrade($buf, 1)
1218 0 361 unless $self->can_write
1221 361 0 if (defined $r) { }
0 0 elsif ($! == 32) { }
0 0 elsif ($! != 4) { }
1224 361 0 unless $len > 0
1230 0 0 if ($self->{'fh'}->can('errstr')) { }
1244 0 315 unless @_ == 2 or @_ == 3
1250 266 49 if ($got)
1251 37 229 $got < $len ? :
1262 0 880 unless $self->can_read
1265 880 0 if (defined $r) { }
0 0 elsif ($! != 4) { }
1266 4 876 unless $r
1270 0 0 if ($self->{'fh'}->can('errstr')) { }
1279 0 315 if ($len and not $allow_partial)
1286 0 1071 unless @_ == 1
1290 1071 199 if ($self->{'rbuf'} =~ s/\A ([^\x0D\x0A]* \x0D?\x0A)//x)
1293 0 199 if (length $self->{'rbuf'} >= $self->{'max_line_size'})
1297 0 199 unless $self->can_read
1299 199 0 if (defined $r) { }
0 0 elsif ($! != 4) { }
1300 0 199 unless $r
1303 0 0 if ($self->{'fh'}->can('errstr')) { }
1316 0 162 unless @_ == 1 or @_ == 2
1325 0 812 if (++$lines >= $self->{'max_header_lines'}) { }
647 165 elsif ($line =~ /\A ([^\x00-\x1F\x7F:]+) : [\x09\x20]* ([^\x0D\x0A]*)/x) { }
3 162 elsif ($line =~ /\A [\x09\x20]+ ([^\x0D\x0A]*)/x) { }
162 0 elsif ($line =~ /\A \x0D?\x0A \z/x) { }
1330 14 633 if (exists $headers->{$field_name}) { }
1332 10 4 unless ref $_ eq "ARRAY"
1342 0 3 unless $val
1344 1 2 unless length $1
1345 1 1 if length $$val
1359 0 18 unless @_ == 2
1362 0 18 if $request->{'cb'}
1385 0 146 unless @_ >= 2 and @_ <= 4 and ref $_[1] eq "HASH"
1389 142 4 defined $prefix_data ? :
1394 880 142 unless exists $headers->{$k}
1398 0 142 ref $v eq 'ARRAY' ? :
1399 0 142 unless defined $_
1407 141 349 if $seen{$field_name}
1408 338 11 if (exists $HeaderCase{$field_name}) { }
1412 5 6 if (exists $header_case->{$field_name}) { }
1418 1 10 unless $field_name =~ /\A $Token+ \z/ox
1422 3 345 ref $v eq 'ARRAY' ? :
1425 0 351 unless $_ eq "" or /\A $Field_Content \z/ox
1427 0 351 unless defined $_
1439 0 137 unless @_ == 3
1442 1 136 ref $te eq 'ARRAY' ? :
1443 10 127 $chunked ? :
1449 0 30 unless @_ == 2
1451 27 3 if (exists $request->{'headers'}{'content-length'}) { }
1452 1 26 unless $request->{'headers'}{'content-length'}
1461 0 226 unless @_ == 3 or @_ == 4
1465 224 2 if (defined $content_length)
1468 9 204 $len > 32768 ? :
1482 0 27 unless @_ == 2
1489 27 154 unless defined $data and length $data
1492 154 0 if ("$]" >= "5.008")
1493 0 154 unless utf8::downgrade($data, 1)
1500 0 27 unless $len == $content_length
1507 0 12 unless @_ == 3
1513 0 110 unless $head =~ /\A ([A-Fa-f0-9]+)/x
1516 12 98 unless my $len = hex $1
1521 0 98 unless $self->read(2) eq "\r\n"
1529 0 5 unless @_ == 2
1536 5 54 unless defined $data and length $data
1539 54 0 if ("$]" >= "5.008")
1540 0 54 unless utf8::downgrade($data, 1)
1554 2 3 if (ref $request->{'trailer_cb'} eq 'CODE') { }
1564 0 149 unless @_ == 1
1569 2 147 unless $line =~ m[\A (HTTP/(0*\d+\.0*\d+)) [\x09\x20]+ ([0-9]{3}) (?: [\x09\x20]+ ([^\x0D\x0A]*) )? \x0D?\x0A]x
1573 2 145 unless defined $reason
1575 2 145 unless $version =~ /0*1\.0*[01]/
1587 0 142 unless @_ == 5
1596 904 0 unless defined $timeout and $timeout >= 0
1599 0 904 unless defined $fd and $fd >= 0
1609 886 18 $type eq 'read' ? :
1612 0 904 if ($nfound == -1)
1613 0 0 unless $! == 4
1615 0 0 if not $timeout or ($pending = $timeout - (time - $initial)) > 0
1625 0 935 unless @_ == 1 or @_ == 2
1627 924 11 if (ref $self->{'fh'} eq "IO::Socket::SSL")
1628 49 875 if $self->{'fh'}->pending
1634 0 18 unless @_ == 1 or @_ == 2
1641 13 0 unless $self->{'keep_alive_timeout'} > 0
1648 43 0 unless $self->{'keep_alive_timeout'} > 0
1654 0 29 unless $ok
1668 8 5 if $self->{'pid'} != $$ or $self->{'tid'} != _get_tid() or length $self->{'rbuf'} or $scheme ne $self->{'scheme'} or $host ne $self->{'host'} or $port ne $self->{'port'} or $peer ne $self->{'peer'} or $self->_has_keep_alive_expired or eval { do { $self->can_read(0) } } or $@
1678 4 23 if (defined $ca_file)
1679 1 3 unless (-r $ca_file)
1690 23 0 if %default_ca
1706 0 0 if -e $ca_bundle
1723 0 154 'threads'->can('tid') ? :
1733 29 0 if (Net::SSLeay::OPENSSL_VERSION_NUMBER() >= 16777216)
1737 22 7 if ($self->{'verify_SSL'}) { }
1751 9 0 if $k =~ /^SSL_/