Branch Coverage

blib/lib/HTTP/Tiny.pm
Criterion Covered Total %
branch 331 478 69.2


line true false branch
83 0 1 if not $persist_ok{$accessor} and $_[1] ne $_[0]{$accessor}
86 1 96 @_ > 1 ? :
93 145 6 if (@_ > 1)
95 2 143 defined $agent && $agent =~ / $/ ? :
102 3 5 if (@_ > 1)
104 2 1 if ($self->{'handle'})
120 2 142 defined $args{'timeout'} ? :
124 15 129 if $args{'cookie_jar'}
127 129 1575 if exists $args{$key}
130 2 140 exists $args{'agent'} ? :
144 139 3 unless (exists $self->{'proxy'})
148 4 138 if (defined $self->{'proxy'}) { }
156 141 1 unless (exists $self->{'http_proxy'})
158 2 139 if $ENV{'REQUEST_METHOD'}
162 10 132 if (defined $self->{'http_proxy'}) { }
171 140 1 unless (exists $self->{'https_proxy'})
175 6 135 if ($self->{'https_proxy'}) { }
184 138 3 unless (ref $self->{'no_proxy'} eq "ARRAY")
186 6 132 defined $self->{'no_proxy'} ? :
209 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"
241 0 1 unless @_ == 3 or @_ == 4 and ref $args eq "HASH"
245 5 2 unless $args->{'headers'}
287 4 1 unless @_ == 3 or @_ == 4 and ref $args eq "HASH"
290 1 4 if (exists $args->{'headers'})
292 0 2 unless $args->{'headers'}
298 3 2 if (-e $file and my $mtime = (stat $file)[9])
304 0 5 unless sysopen my $fh, $tempfile, 193
309 0 5 unless close $fh
312 3 2 if ($response->{'success'})
313 0 3 unless rename $tempfile, $file
316 3 0 if ($lm and my $mtime = $self->_parse_http_date($lm))
436 4 111 unless @_ == 3 or @_ == 4 and ref $args eq "HASH"
444 10 0 unless $@ and $idempotent{$method} and $@ =~ /^(?:Socket closed|Unexpected end|SSL read error)/
448 10 129 if (my $e = $@)
450 0 0 if (ref $e eq "HASH" and exists $e->{'status'})
451 0 0 unless $args->{'_redirects'}
0 0 if @{[] unless $args->{'_redirects'};}
467 9 1 unless $args->{'_redirects'}
0 10 @{[] unless $args->{'_redirects'};} ? :
489 0 6 unless @_ == 2 and ref $data
491 0 6 unless ref $data eq "HASH" or ref $data eq "ARRAY"
494 2 4 ref $data eq 'HASH' ? :
495 0 6 unless @params % 2 == 0
501 1 13 unless defined $key
503 0 13 if (ref $value eq 'ARRAY') { }
511 3 2 ref $data eq 'ARRAY' ? :
538 13 0 if $INC[-1] eq "."
539 0 13 unless (eval { do { require IO::Socket::SSL; "IO::Socket::SSL"->VERSION("1.42") } })
545 0 13 unless (eval { do { require Net::SSLeay; "Net::SSLeay"->VERSION("1.49") } })
551 2 1 if (ref $self and $self->{'verify_SSL'} || $self->{'SSL_options'}{'SSL_verify_mode'})
556 1 1 unless (eval { do { $handle->_find_CA_file; 1 } })
562 10 3 wantarray ? :
586 0 0 if ($self->{'handle'})
605 144 0 if defined $version
614 1 149 if ($scheme ne "http" and $scheme ne "https")
623 147 2 $port == $DefaultPort{$scheme} ? :
631 0 149 if ("CODE" eq ref $peer)
639 13 136 if ($handle)
640 10 3 unless ($handle->can_reuse($scheme, $host, $port, $peer))
654 34 107 if $self->{'cookie_jar'}
658 2 139 if ($method eq 'HEAD' or $response->{'status'} =~ /^[23]04/) { }
664 11 128 @redir_args ? :
669 29 111 if ($self->{'keep_alive'} and $handle->connected and $known_message_length and $response->{'protocol'} eq 'HTTP/1.1' and ($response->{'headers'}{'connection'} || '') ne 'close') { }
685 11 129 if (@redir_args)
692 9 120 if @{$args->{'_redirects'};}
707 2 144 if ($self->{'_has_proxy'}{$scheme} and not grep({$host =~ /\Q$_\E$/;} @{$$self{'no_proxy'};})) { }
719 0 2 if ($request->{'scheme'} eq 'https') { }
720 0 0 unless $self->{'https_proxy'}
722 0 0 if ($proxy_vars[0] eq "https")
727 0 2 unless $self->{'http_proxy'}
733 1 1 if (length $p_auth and not defined $request->{'headers'}{'proxy-authorization'})
739 0 2 if ($request->{'scheme'} eq 'https') { }
755 0 21 unless (defined $scheme and length $scheme and length $host and length $port and $path_query eq "/")
771 0 0 exists $request->{'headers'}{'user-agent'} ? :
782 0 0 if ($request->{'headers'}{'proxy-authorization'})
794 0 0 unless (substr($response->{'status'}, 0, 1) eq 2)
808 266 24 unless defined $_
815 1 144 if (exists $request->{'headers'}{'host'})
822 110 34 unless $self->{'keep_alive'}
825 42 102 if ($request->{'method'} eq "PUT" or $request->{'method'} eq "POST")
826 16 26 unless (defined $args->{'content'} and length $args->{'content'})
831 27 117 if (defined $args->{'content'})
832 5 22 if (ref $args->{'content'} eq 'CODE') { }
21 1 elsif (length $args->{'content'}) { }
833 0 5 if (exists $request->{'content-length'} and $request->{'content-length'} == 0) { }
840 3 0 unless exists $request->{'headers'}{'content-length'} or $request->{'headers'}{'transfer-encoding'}
846 21 0 if ($] ge "5.008")
847 0 21 unless utf8::downgrade($content, 1)
853 20 0 unless $request->{'headers'}{'content-length'} or $request->{'headers'}{'transfer-encoding'}
857 1 26 if ref $args->{'trailer_callback'} eq "CODE"
861 34 110 if ($self->{'cookie_jar'})
863 22 12 if length $cookies
867 4 140 if (length $auth and not defined $request->{'headers'}{'authorization'})
887 135 4 unless ($data_cb and $response->{'status'} =~ /^2/)
888 1 134 if (defined $self->{'max_size'}) { }
892 1 0 if length $_[1]{'content'} > $self->{'max_size'}
906 4 30 unless defined $cookies
908 2 28 ref $cookies ? :
920 2 27 unless ref $jar and ref($jar)->can($method)
933 11 2 if ($status eq '303' || $status =~ /^30[1278]/ && $method =~ /^GET|HEAD$/ and $headers->{'location'} and @{$args->{'_redirects'};} < $self->{'max_redirect'})
939 1 10 $headers->{'location'} =~ m[^/] ? :
940 2 9 $status eq '303' ? :
949 1 185 unless my($scheme, $host, $path_query) = $url =~ m[\A([^:/?#]+)://([^/?#]*)([^#]*)]
953 46 139 unless $path_query =~ m[\A/]
956 12 173 if ((my $i = index($host, "\@")) != -1)
964 11 2 $scheme eq 'https' ? :
151 13 $scheme eq 'http' ? :
21 164 $host =~ s/:(\d*)\z// && length $1 ? :
969 183 2 length $host ? :
988 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)$/) { }
998 9 0 @tl_parts ? :
999 0 9 $t < 0 ? :
1012 2 24 unless defined $str
1013 24 0 if ($] ge '5.008') { }
1018 0 0 if length $str == do { use bytes; length $str }
1071 2 0 if (@_ > 1)
1073 0 2 if ($self->{'fh'} and $self->{'fh'}->can("timeout"))
1081 0 12 unless @_ == 5
1084 9 3 if ($scheme eq "https")
1096 1 11 $self->{'local_address'} ? :
1 11 unless $self->{'fh'} = $SOCKET_CLASS->new("PeerHost", $peer, "PeerPort", $port, $self->{'local_address'} ? ("LocalAddr", $self->{'local_address'}) : (), "Proto", "tcp", "Type", 1, "Timeout", $self->{'timeout'})
1099 0 11 unless binmode $self->{'fh'}
1101 11 0 if ($self->{'keep_alive'})
1102 0 11 unless (defined $self->{'fh'}->setsockopt(1, 9, 1))
1108 9 2 if $scheme eq "https"
1122 8 0 if ($self->{'fh'} and $self->{'fh'}->connected)
1125 0 8 wantarray ? :
1136 0 9 if (ref $self->{'fh'} eq "IO::Socket::SSL")
1137 0 0 unless ($self->{'fh'}->stop_SSL)
1153 3 6 unless (ref $self->{'fh'} eq "IO::Socket::SSL")
1160 0 0 unless @_ == 1
1163 0 0 unless CORE::close $self->{'fh'}
1167 0 359 unless @_ == 2
1170 359 0 if ($] ge "5.008")
1171 0 359 unless utf8::downgrade($buf, 1)
1181 0 359 unless $self->can_write
1184 359 0 if (defined $r) { }
0 0 elsif ($! == 32) { }
0 0 elsif ($! != 4) { }
1187 359 0 unless $len > 0
1193 0 0 if ($self->{'fh'}->can('errstr')) { }
1207 0 682 unless @_ == 2 or @_ == 3
1213 638 44 if ($got)
1214 36 602 $got < $len ? :
1225 0 471 unless $self->can_read
1228 471 0 if (defined $r) { }
0 0 elsif ($! != 4) { }
1229 4 467 unless $r
1233 0 0 if ($self->{'fh'}->can('errstr')) { }
1242 0 682 if ($len and not $allow_partial)
1249 0 1230 unless @_ == 1
1253 1230 201 if ($self->{'rbuf'} =~ s/\A ([^\x0D\x0A]* \x0D?\x0A)//x)
1256 0 201 if (length $self->{'rbuf'} >= $self->{'max_line_size'})
1260 0 201 unless $self->can_read
1262 201 0 if (defined $r) { }
0 0 elsif ($! != 4) { }
1263 0 201 unless $r
1266 0 0 if ($self->{'fh'}->can('errstr')) { }
1279 0 168 unless @_ == 1 or @_ == 2
1288 0 782 if (++$lines >= $self->{'max_header_lines'}) { }
611 171 elsif ($line =~ /\A ([^\x00-\x1F\x7F:]+) : [\x09\x20]* ([^\x0D\x0A]*)/x) { }
3 168 elsif ($line =~ /\A [\x09\x20]+ ([^\x0D\x0A]*)/x) { }
168 0 elsif ($line =~ /\A \x0D?\x0A \z/x) { }
1293 19 592 if (exists $headers->{$field_name}) { }
1295 13 6 unless ref $_ eq "ARRAY"
1305 0 3 unless $val
1307 1 2 unless length $1
1308 1 1 if length $$val
1322 0 8 unless @_ == 2
1325 0 8 if $request->{'cb'}
1348 0 148 unless @_ >= 2 and @_ <= 4 and ref $_[1] eq "HASH"
1352 144 4 defined $prefix_data ? :
1357 892 144 unless exists $headers->{$k}
1361 0 144 ref $v eq 'ARRAY' ? :
1362 0 144 unless defined $_
1370 143 370 if $seen{$field_name}
1371 359 11 if (exists $HeaderCase{$field_name}) { }
1375 5 6 if (exists $header_case->{$field_name}) { }
1381 1 10 unless $field_name =~ /\A $Token+ \z/ox
1385 3 366 ref $v eq 'ARRAY' ? :
1388 0 372 unless $_ eq "" or /\A $Field_Content \z/ox
1390 0 372 unless defined $_
1402 0 139 unless @_ == 3
1405 1 138 ref $te eq 'ARRAY' ? :
1406 14 125 $chunked ? :
1412 0 26 unless @_ == 2
1414 23 3 if (exists $request->{'headers'}{'content-length'}) { }
1415 1 22 unless $request->{'headers'}{'content-length'}
1424 0 407 unless @_ == 3 or @_ == 4
1428 405 2 if (defined $content_length)
1431 9 388 $len > 32768 ? :
1445 0 23 unless @_ == 2
1452 23 150 unless defined $data and length $data
1455 150 0 if ($] ge "5.008")
1456 0 150 unless utf8::downgrade($data, 1)
1463 0 23 unless $len == $content_length
1470 0 16 unless @_ == 3
1476 0 297 unless $head =~ /\A ([A-Fa-f0-9]+)/x
1479 16 281 unless my $len = hex $1
1484 0 281 unless $self->read(2) eq "\r\n"
1492 0 5 unless @_ == 2
1499 5 54 unless defined $data and length $data
1502 54 0 if ($] ge "5.008")
1503 0 54 unless utf8::downgrade($data, 1)
1517 2 3 if (ref $request->{'trailer_cb'} eq 'CODE') { }
1527 0 151 unless @_ == 1
1532 2 149 unless $line =~ m[\A (HTTP/(0*\d+\.0*\d+)) [\x09\x20]+ ([0-9]{3}) (?: [\x09\x20]+ ([^\x0D\x0A]*) )? \x0D?\x0A]x
1536 2 147 unless defined $reason
1538 2 147 unless $version =~ /0*1\.0*[01]/
1550 0 144 unless @_ == 5
1559 474 0 unless defined $timeout and $timeout >= 0
1562 0 474 unless defined $fd and $fd >= 0
1572 466 8 $type eq 'read' ? :
1575 0 474 if ($nfound == -1)
1576 0 0 unless $! == 4
1578 0 0 if not $timeout or ($pending = $timeout - (time - $initial)) > 0
1588 0 516 unless @_ == 1 or @_ == 2
1590 508 8 if (ref $self->{'fh'} eq "IO::Socket::SSL")
1591 50 458 if $self->{'fh'}->pending
1597 0 8 unless @_ == 1 or @_ == 2
1604 0 9 unless $ok
1617 7 3 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 eval { do { $self->can_read(0) } } or $@
1630 1 4 defined $self->{'SSL_options'}{'SSL_ca_file'} ? :
1632 1 4 if (defined $ca_file)
1633 1 0 unless (-r $ca_file)
1640 3 1 if $INC[-1] eq "."
1642 4 0 if eval { do { require Mozilla::CA; 1 } }
1655 0 0 if -e $ca_bundle
1665 0 155 'threads'->can('tid') ? :
1675 9 0 if (Net::SSLeay::OPENSSL_VERSION_NUMBER() >= 16777216)
1679 3 6 if ($self->{'verify_SSL'}) { }
1692 18 0 if $k =~ /^SSL_/