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'}
286 4 1 unless @_ == 3 or @_ == 4 and ref $args eq "HASH"
289 1 4 if (exists $args->{'headers'})
291 0 2 unless $args->{'headers'}
297 3 2 if (-e $file and my $mtime = (stat $file)[9])
303 0 5 unless sysopen my $fh, $tempfile, 193
308 0 5 unless close $fh
311 3 2 if ($response->{'success'})
312 0 3 unless rename $tempfile, $file
315 3 0 if ($lm and my $mtime = $self->_parse_http_date($lm))
431 4 111 unless @_ == 3 or @_ == 4 and ref $args eq "HASH"
439 10 0 unless $@ and $idempotent{$method} and $@ =~ /^(?:Socket closed|Unexpected end|SSL read error)/
443 10 129 if (my $e = $@)
445 0 0 if (ref $e eq "HASH" and exists $e->{'status'})
446 0 0 unless $args->{'_redirects'}
0 0 if @{[] unless $args->{'_redirects'};}
462 9 1 unless $args->{'_redirects'}
0 10 @{[] unless $args->{'_redirects'};} ? :
484 0 6 unless @_ == 2 and ref $data
486 0 6 unless ref $data eq "HASH" or ref $data eq "ARRAY"
489 2 4 ref $data eq 'HASH' ? :
490 0 6 unless @params % 2 == 0
496 1 13 unless defined $key
498 0 13 if (ref $value eq 'ARRAY') { }
506 3 2 ref $data eq 'ARRAY' ? :
533 13 0 if $INC[-1] eq "."
534 0 13 unless (eval { do { require IO::Socket::SSL; "IO::Socket::SSL"->VERSION("1.42") } })
540 0 13 unless (eval { do { require Net::SSLeay; "Net::SSLeay"->VERSION("1.49") } })
546 2 1 if (ref $self and $self->{'verify_SSL'} || $self->{'SSL_options'}{'SSL_verify_mode'})
551 1 1 unless (eval { do { $handle->_find_CA_file; 1 } })
557 10 3 wantarray ? :
581 0 0 if ($self->{'handle'})
600 144 0 if defined $version
609 1 149 if ($scheme ne "http" and $scheme ne "https")
618 147 2 $port == $DefaultPort{$scheme} ? :
626 0 149 if ("CODE" eq ref $peer)
634 13 136 if ($handle)
635 10 3 unless ($handle->can_reuse($scheme, $host, $port, $peer))
649 34 107 if $self->{'cookie_jar'}
653 2 139 if ($method eq 'HEAD' or $response->{'status'} =~ /^[23]04/) { }
659 11 128 @redir_args ? :
664 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') { }
680 11 129 if (@redir_args)
687 9 120 if @{$args->{'_redirects'};}
702 2 144 if ($self->{'_has_proxy'}{$scheme} and not grep({$host =~ /\Q$_\E$/;} @{$$self{'no_proxy'};})) { }
714 0 2 if ($request->{'scheme'} eq 'https') { }
715 0 0 unless $self->{'https_proxy'}
717 0 0 if ($proxy_vars[0] eq "https")
722 0 2 unless $self->{'http_proxy'}
728 1 1 if (length $p_auth and not defined $request->{'headers'}{'proxy-authorization'})
734 0 2 if ($request->{'scheme'} eq 'https') { }
750 0 21 unless (defined $scheme and length $scheme and length $host and length $port and $path_query eq "/")
766 0 0 exists $request->{'headers'}{'user-agent'} ? :
777 0 0 if ($request->{'headers'}{'proxy-authorization'})
789 0 0 unless (substr($response->{'status'}, 0, 1) eq 2)
803 266 24 unless defined $_
810 1 144 if (exists $request->{'headers'}{'host'})
817 110 34 unless $self->{'keep_alive'}
820 42 102 if ($request->{'method'} eq "PUT" or $request->{'method'} eq "POST")
821 16 26 unless (defined $args->{'content'} and length $args->{'content'})
826 27 117 if (defined $args->{'content'})
827 5 22 if (ref $args->{'content'} eq 'CODE') { }
21 1 elsif (length $args->{'content'}) { }
828 0 5 if (exists $request->{'content-length'} and $request->{'content-length'} == 0) { }
835 3 0 unless exists $request->{'headers'}{'content-length'} or $request->{'headers'}{'transfer-encoding'}
841 21 0 if ($] ge "5.008")
842 0 21 unless utf8::downgrade($content, 1)
848 20 0 unless $request->{'headers'}{'content-length'} or $request->{'headers'}{'transfer-encoding'}
852 1 26 if ref $args->{'trailer_callback'} eq "CODE"
856 34 110 if ($self->{'cookie_jar'})
858 22 12 if length $cookies
862 4 140 if (length $auth and not defined $request->{'headers'}{'authorization'})
882 135 4 unless ($data_cb and $response->{'status'} =~ /^2/)
883 1 134 if (defined $self->{'max_size'}) { }
887 1 0 if length $_[1]{'content'} > $self->{'max_size'}
901 4 30 unless defined $cookies
903 2 28 ref $cookies ? :
915 2 27 unless ref $jar and ref($jar)->can($method)
928 11 2 if ($status eq '303' || $status =~ /^30[1278]/ && $method =~ /^GET|HEAD$/ and $headers->{'location'} and @{$args->{'_redirects'};} < $self->{'max_redirect'})
934 1 10 $headers->{'location'} =~ m[^/] ? :
935 2 9 $status eq '303' ? :
944 1 185 unless my($scheme, $host, $path_query) = $url =~ m[\A([^:/?#]+)://([^/?#]*)([^#]*)]
948 46 139 unless $path_query =~ m[\A/]
951 12 173 if ((my $i = index($host, "\@")) != -1)
959 11 2 $scheme eq 'https' ? :
151 13 $scheme eq 'http' ? :
21 164 $host =~ s/:(\d*)\z// && length $1 ? :
964 183 2 length $host ? :
983 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)$/) { }
993 9 0 @tl_parts ? :
994 0 9 $t < 0 ? :
1007 2 24 unless defined $str
1008 24 0 if ($] ge '5.008') { }
1013 0 0 if length $str == do { use bytes; length $str }
1066 2 0 if (@_ > 1)
1068 0 2 if ($self->{'fh'} and $self->{'fh'}->can("timeout"))
1076 0 12 unless @_ == 5
1079 9 3 if ($scheme eq "https")
1091 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'})
1094 0 11 unless binmode $self->{'fh'}
1096 11 0 if ($self->{'keep_alive'})
1097 0 11 unless (defined $self->{'fh'}->setsockopt(1, 9, 1))
1103 9 2 if $scheme eq "https"
1117 8 0 if ($self->{'fh'} and $self->{'fh'}->connected)
1120 0 8 wantarray ? :
1131 0 9 if (ref $self->{'fh'} eq "IO::Socket::SSL")
1132 0 0 unless ($self->{'fh'}->stop_SSL)
1148 3 6 unless (ref $self->{'fh'} eq "IO::Socket::SSL")
1155 0 0 unless @_ == 1
1158 0 0 unless CORE::close $self->{'fh'}
1162 0 359 unless @_ == 2
1165 359 0 if ($] ge "5.008")
1166 0 359 unless utf8::downgrade($buf, 1)
1176 0 359 unless $self->can_write
1179 359 0 if (defined $r) { }
0 0 elsif ($! == 32) { }
0 0 elsif ($! != 4) { }
1182 359 0 unless $len > 0
1188 0 0 if ($self->{'fh'}->can('errstr')) { }
1202 0 674 unless @_ == 2 or @_ == 3
1208 639 35 if ($got)
1209 23 616 $got < $len ? :
1220 0 323 unless $self->can_read
1223 323 0 if (defined $r) { }
0 0 elsif ($! != 4) { }
1224 4 319 unless $r
1228 0 0 if ($self->{'fh'}->can('errstr')) { }
1237 0 674 if ($len and not $allow_partial)
1244 0 1227 unless @_ == 1
1248 1227 201 if ($self->{'rbuf'} =~ s/\A ([^\x0D\x0A]* \x0D?\x0A)//x)
1251 0 201 if (length $self->{'rbuf'} >= $self->{'max_line_size'})
1255 0 201 unless $self->can_read
1257 201 0 if (defined $r) { }
0 0 elsif ($! != 4) { }
1258 0 201 unless $r
1261 0 0 if ($self->{'fh'}->can('errstr')) { }
1274 0 168 unless @_ == 1 or @_ == 2
1283 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) { }
1288 17 594 if (exists $headers->{$field_name}) { }
1290 13 4 unless ref $_ eq "ARRAY"
1300 0 3 unless $val
1302 1 2 unless length $1
1303 1 1 if length $$val
1317 0 8 unless @_ == 2
1320 0 8 if $request->{'cb'}
1343 0 148 unless @_ >= 2 and @_ <= 4 and ref $_[1] eq "HASH"
1347 144 4 defined $prefix_data ? :
1352 892 144 unless exists $headers->{$k}
1356 0 144 ref $v eq 'ARRAY' ? :
1357 0 144 unless defined $_
1365 144 369 if $seen{$field_name}
1366 358 11 if (exists $HeaderCase{$field_name}) { }
1370 5 6 if (exists $header_case->{$field_name}) { }
1376 1 10 unless $field_name =~ /\A $Token+ \z/ox
1380 3 365 ref $v eq 'ARRAY' ? :
1383 0 371 unless $_ eq "" or /\A $Field_Content \z/ox
1385 0 371 unless defined $_
1397 0 139 unless @_ == 3
1400 1 138 ref $te eq 'ARRAY' ? :
1401 14 125 $chunked ? :
1407 0 26 unless @_ == 2
1409 23 3 if (exists $request->{'headers'}{'content-length'}) { }
1410 1 22 unless $request->{'headers'}{'content-length'}
1419 0 404 unless @_ == 3 or @_ == 4
1423 402 2 if (defined $content_length)
1426 7 385 $len > 32768 ? :
1440 0 23 unless @_ == 2
1447 23 150 unless defined $data and length $data
1450 150 0 if ($] ge "5.008")
1451 0 150 unless utf8::downgrade($data, 1)
1458 0 23 unless $len == $content_length
1465 0 16 unless @_ == 3
1471 0 294 unless $head =~ /\A ([A-Fa-f0-9]+)/x
1474 16 278 unless my $len = hex $1
1479 0 278 unless $self->read(2) eq "\r\n"
1487 0 5 unless @_ == 2
1494 5 54 unless defined $data and length $data
1497 54 0 if ($] ge "5.008")
1498 0 54 unless utf8::downgrade($data, 1)
1512 2 3 if (ref $request->{'trailer_cb'} eq 'CODE') { }
1522 0 151 unless @_ == 1
1527 2 149 unless $line =~ m[\A (HTTP/(0*\d+\.0*\d+)) [\x09\x20]+ ([0-9]{3}) (?: [\x09\x20]+ ([^\x0D\x0A]*) )? \x0D?\x0A]x
1531 2 147 unless defined $reason
1533 2 147 unless $version =~ /0*1\.0*[01]/
1545 0 144 unless @_ == 5
1554 338 0 unless defined $timeout and $timeout >= 0
1557 0 338 unless defined $fd and $fd >= 0
1567 330 8 $type eq 'read' ? :
1570 0 338 if ($nfound == -1)
1571 0 0 unless $! == 4
1573 0 0 if not $timeout or ($pending = $timeout - (time - $initial)) > 0
1583 0 368 unless @_ == 1 or @_ == 2
1585 364 4 if (ref $self->{'fh'} eq "IO::Socket::SSL")
1586 38 326 if $self->{'fh'}->pending
1592 0 8 unless @_ == 1 or @_ == 2
1599 0 9 unless $ok
1612 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 $@
1625 1 4 defined $self->{'SSL_options'}{'SSL_ca_file'} ? :
1627 1 4 if (defined $ca_file)
1628 1 0 unless (-r $ca_file)
1635 3 1 if $INC[-1] eq "."
1637 4 0 if eval { do { require Mozilla::CA; 1 } }
1650 0 0 if -e $ca_bundle
1660 0 155 'threads'->can('tid') ? :
1670 9 0 if (Net::SSLeay::OPENSSL_VERSION_NUMBER() >= 16777216)
1674 3 6 if ($self->{'verify_SSL'}) { }
1687 18 0 if $k =~ /^SSL_/