Branch Coverage

blib/lib/FCGI/Buffer.pm
Criterion Covered Total %
branch 177 530 33.4


line true false branch
110 1 38 unless (defined $class)
128 20 18 if ($ENV{'SERVER_PROTOCOL'} and $ENV{'SERVER_PROTOCOL'} eq 'HTTP/1.1' || $ENV{'SERVER_PROTOCOL'} eq 'HTTP/2.0') { }
139 37 0 if (defined $^V and $^V ge "v5.14.0")
140 0 37 if ${^GLOBAL_PHASE} eq "DESTRUCT"
144 1 36 if ($self->{'logger'})
148 0 37 unless (defined $self->{'buf'} and defined $self->{'buf'}->getpos)
150 0 0 if ($self->{'logger'})
162 1 36 if ($self->{'logger'})
163 0 1 if ($ENV{'HTTP_IF_NONE_MATCH'})
166 0 1 if ($ENV{'HTTP_IF_MODIFIED_SINCE'})
173 3 34 unless ($headers or $self->is_cached)
174 0 3 if ($self->{'logger'})
177 3 0 unless (defined $headers)
181 3 0 unless (defined $self->{'status'})
190 1 33 if ($ENV{'REQUEST_METHOD'} and $ENV{'REQUEST_METHOD'} eq 'HEAD') { }
196 34 0 if ($headers)
200 2 32 if (defined $self->{'body'} and $self->{'body'} eq '') { }
29 3 elsif (defined $self->{'content_type'}) { }
204 0 2 if ($self->{'cache'})
210 29 0 if (defined $content_type[0] and lc $content_type[0] eq "text" and lc($content_type[1]) =~ /^html/ and defined $self->{'body'})
211 25 4 if ($self->{'optimise_content'})
215 0 25 if ($self->{'logger'})
222 24 1 if ($self->{'optimise_content'} == 1) { }
228 1 2 if $newlength >= $oldlength
237 22 3 unless (defined $self->{'info'})
238 0 22 if ($self->{'cache'}) { }
248 10 15 unless ($protocol)
259 18 7 if (my $script_name = $ENV{'SCRIPT_NAME'})
260 18 0 if ($script_name =~ m[^/])
286 1 24 if ($self->{'optimise_content'} >= 2)
293 1 24 if ($self->{'optimise_content'} >= 2)
299 1 0 if $newlength >= $oldlength
304 3 26 if ($self->{'lint_content'})
308 0 3 if ($self->{'logger'})
315 1 2 if ($lint->errors)
321 0 3 if ($self->{'logger'}) { }
333 1 33 if (defined $headers and $headers =~ /^Status: (\d+)/m) { }
25 8 elsif (defined $self->{'info'}) { }
341 1 33 if ($self->{'logger'})
348 11 8 if ($ENV{'SERVER_PROTOCOL'} and $ENV{'SERVER_PROTOCOL'} eq 'HTTP/1.1' || $ENV{'SERVER_PROTOCOL'} eq 'HTTP/2.0' and $self->{'generate_etag'} and defined $self->{'body'})
353 2 2 if ($ENV{'HTTP_IF_NONE_MATCH'} and $self->{'generate_304'} and $self->{'status'} == 200)
359 0 34 if (my $save_to = $self->{'save_to'})
361 0 0 if ($self->{'logger'})
364 0 0 if (not -r $sqlite_file) { }
365 0 0 unless (-d $save_to->{'directory'})
369 0 0 if ($self->{'save_to'}{'create_table'})
380 32 2 if (defined $unzipped_body)
381 0 32 $ENV{'Range'} ? :
383 3 29 if ($range and not $self->{'cache'})
385 3 0 if ($range =~ /^bytes=(\d*)-(\d*)/)
386 1 2 if ($1 and $2) { }
1 1 elsif ($1) { }
1 0 elsif ($2) { }
400 0 34 if ($self->{'cache'}) { }
26 8 elsif ($self->{'info'}) { }
407 0 0 if (not defined $self->{'body'}) { }
408 0 0 if ($self->{'send_body'})
410 0 0 if (defined $self->{'cobject'}) { }
0 0 elsif ($self->{'logger'}) { }
415 0 0 if ($self->{'info'}) { }
432 0 0 if ($self->{'send_body'} and $ENV{'SERVER_PROTOCOL'} and $ENV{'SERVER_PROTOCOL'} eq 'HTTP/1.1' || $ENV{'SERVER_PROTOCOL'} eq 'HTTP/2.0' and $self->{'generate_304'} and $self->{'status'} == 200)
435 0 0 if ($ENV{'HTTP_IF_MODIFIED_SINCE'})
442 0 0 if ($self->{'send_body'} and $self->{'status'} == 200 and defined $cache_hash)
444 0 0 if ($dbh)
446 0 0 if ($changes and my $ttl = $self->{'save_to'}{'ttl'})
450 0 0 unless (defined $self->{'body'})
459 0 0 if ($dbh)
462 0 0 if ($self->{'logger'})
465 0 0 if ($sth->execute and my $href = $sth->fetchrow_hashref)
466 0 0 if (my $path = $href->{'path'})
472 0 0 if ($self->{'logger'})
479 0 0 if ($self->{'logger'}) { }
490 0 0 if ($self->{'send_body'} and $ENV{'SERVER_PROTOCOL'} and $ENV{'SERVER_PROTOCOL'} eq 'HTTP/1.1' || $ENV{'SERVER_PROTOCOL'} eq 'HTTP/2.0' and $self->{'status'} == 200)
493 0 0 if ($ENV{'HTTP_IF_NONE_MATCH'} and $self->{'generate_etag'})
494 0 0 unless (defined $self->{'etag'})
500 0 0 if ($self->{'status'} == 200)
502 0 0 if ($self->{'send_body'})
503 0 0 if ($self->{'generate_etag'} and not defined $self->{'etag'} and not defined $headers && $headers =~ /^ETag: /m)
510 0 0 unless ($self->{'etag'})
511 0 0 if (defined $headers and $headers =~ /^ETag: "([a-z0-9]{32})"/m) { }
517 0 0 if ($ENV{'HTTP_IF_NONE_MATCH'} and $self->{'send_body'} and $self->{'status'} != 304 and $self->{'generate_304'})
518 0 0 unless ($self->_check_if_none_match)
522 0 0 if ($self->{'cobject'})
523 0 0 if ($ENV{'HTTP_IF_MODIFIED_SINCE'} and $self->{'status'} != 304 and not $cannot_304)
529 0 0 if ($self->{'status'} == 200 and $self->{'generate_last_modified'})
530 0 0 if ($self->{'logger'})
538 0 0 if ($self->{'status'} == 200)
541 0 0 unless ($self->{'cache_age'})
548 0 0 if ($changes and $encoding)
551 0 0 if ($self->{'o'} and scalar @{$self->{'o'};}) { }
0 0 elsif (defined $headers and length $headers) { }
555 0 0 if (defined $headers and length $headers) { }
563 0 0 if (length $c)
570 0 0 if (length $headers)
574 0 0 if ($self->{'generate_etag'})
575 0 0 unless (defined $self->{'etag'})
583 0 0 if ($self->{'logger'})
590 0 0 if ($dbh and $self->{'info'} and $self->{'save_to'} and my $request_uri = $ENV{'REQUEST_URI'})
592 0 0 if ($self->{'logger'})
597 0 0 if (my $href = $sth->fetchrow_hashref) { }
598 0 0 if (my $ttl = $self->{'save_to'}{'ttl'})
606 0 0 if ($self->{'lingua'}) { }
608 0 0 if ($language =~ /([\w\s]+)/i)
615 0 0 if ($bdir =~ m(^([/\\])(.+)$))
620 0 0 if ($self->{'logger'})
627 0 0 if ($path =~ /^(.+)$/)
631 0 0 if (open my $fout, '>', $path) { }
643 0 0 unless ($self->{'_encode_loaded'})
652 0 0 if ($self->{'logger'})
657 0 0 if ($changes and my $ttl = $self->{'save_to'}{'ttl'})
661 0 0 if ($self->{'logger'})
667 0 0 if ($self->{'generate_last_modified'})
669 0 0 if (defined $self->{'cobject'}) { }
676 0 0 if ($self->{'info'}) { }
678 0 0 if (defined $self->{'x_cache'}) { }
685 0 0 if (defined $self->{'x_cache'}) { }
700 26 0 if ($self->{'generate_last_modified'})
701 8 18 if (my $age = $self->_my_age)
705 3 0 if ($ENV{'HTTP_IF_MODIFIED_SINCE'} and $self->{'status'} != 304 and $self->{'generate_304'})
711 0 26 if ($self->_save_to($unzipped_body, $dbh) and $encoding)
751 11 23 if ($self->{'generate_etag'} and not defined $headers && $headers =~ /^ETag: /m)
752 11 0 if (defined $self->{'etag'}) { }
0 0 elsif ($self->{'logger'} and $self->{'status'} == 200 || $self->{'status'} == 304 and $self->{'body'} and not $ENV{'NO_CACHE'} and not $self->is_cached) { }
754 0 11 if ($self->{'logger'})
777 32 2 if (defined $self->{'body'}) { }
778 1 31 if (utf8::is_utf8($self->{'body'}))
786 34 0 if (defined $headers and length $headers) { }
790 30 2 if ($self->{'body'} and $self->{'send_body'})
791 30 0 unless (grep /^Content-Length: \d/, @{$$self{"o"};})
795 31 3 unless (grep /^Status: \d/, @{$$self{"o"};})
805 30 2 if ($body_length and $self->{'send_body'})
810 34 0 if (do {
817 0 0 if ($self->{'logger'})
846 4 30 if (not $self->{'send_body'} && defined $self->{'body'})
854 0 11 if defined $self->{'etag'}
855 0 11 unless defined $self->{'body'}
857 11 0 unless (defined $self->{'_encode_loaded'})
863 0 11 if ($self->{'logger'})
871 0 3 if ($self->{'logger'})
875 0 3 unless ($self->{'generate_304'})
880 0 3 unless (defined $params->{'since'})
884 1 2 unless (defined $s)
885 0 1 if ($self->{'logger'})
892 2 0 unless (defined $age)
893 0 2 if ($self->{'logger'})
898 0 0 if ($age > $s)
899 0 0 if ($self->{'logger'})
906 0 0 if ($self->{'logger'})
909 0 0 if ($params->{'modified'} <= $s)
913 0 0 if ($self->{'logger'})
979 0 0 if ($self->{'cache_key'})
982 0 0 unless (defined $self->{'info'})
988 0 0 if ($self->{'lingua'})
991 0 0 if ($ENV{'HTTP_COOKIE'})
996 0 0 unless ($cookie =~ /^__utm[abcz]/)
1004 0 0 if ($headers and $headers =~ /^Vary: .*$/m)
1005 0 0 if (defined $self->{'logger'})
1010 0 0 if (lc $h1_name eq "vary")
1013 0 0 if ($h2_name eq $h1_value)
1024 0 0 if (defined $self->{'logger'})
1113 22 10 ref $_[0] eq 'HASH' ? :
1116 9 23 if (defined $params{'generate_etag'})
1119 0 32 if (defined $params{'generate_last_modified'})
1122 1 31 if (defined $params{'compress_content'})
1125 31 1 if (defined $params{'optimise_content'})
1128 4 28 if (defined $params{'lint_content'})
1131 1 31 if (defined $params{'logger'})
1134 0 32 if (defined $params{'lingua'})
1138 1 31 if (defined $params{'save_to'} and $self->can_cache) { }
0 62 elsif (exists $params{'save_to'} and not defined $params{'save_to'}) { }
1139 1 0 if (my $dir = $params{'save_to'}{'directory'})
1140 1 0 unless (-d $dir)
1142 1 0 unless (-d $dir)
1147 0 0 unless (-w $dir)
1153 0 0 unless (exists $params{'save_to'}{'ttl'})
1159 3 28 if (defined $params{'generate_304'})
1162 4 27 if (defined $params{'info'} and not defined $self->{'info'})
1168 0 31 if ($pos > 0)
1169 0 0 if (defined $self->{'logger'}) { }
1177 0 31 if (exists $params{'cache'} and $self->can_cache)
1178 0 0 if (defined $ENV{'HTTP_CACHE_CONTROL'})
1180 0 0 if (defined $self->{'logger'})
1183 0 0 if ($control =~ /^max-age\s*=\s*(\d+)$/)
1187 0 0 if (defined $self->{'logger'})
1193 0 0 if (not defined $params{'cache'} and defined $self->{'cache'}) { }
1194 0 0 if (defined $self->{'logger'})
1195 0 0 if ($self->{'cache_key'}) { }
1205 0 0 if (defined $params{'cache_key'})
1217 11 0 unless scalar @_
1230 8 3 ref $_[0] eq 'HASH' ? :
1245 1 8 if (defined $self->{'x_cache'})
1248 0 8 if (defined $ENV{'NO_CACHE'} or defined $ENV{'NO_STORE'})
1252 0 8 if (defined $ENV{'HTTP_CACHE_CONTROL'})
1254 0 0 if (defined $self->{'logger'})
1258 0 0 if ($control eq "no-store" or $control eq "no-cache" or $control eq "max-age=0" or $control eq "private")
1312 12 0 unless ($self->{'cache'})
1313 0 12 if ($self->{'logger'})
1325 0 0 if ($self->{'logger'})
1329 0 0 unless ($self->{'cobject'})
1330 0 0 if ($self->{'logger'})
1335 0 0 unless ($self->{'cobject'}->value($key))
1336 0 0 if ($self->{'logger'})
1346 0 0 unless (defined $age)
1347 0 0 if ($self->{'logger'})
1355 0 0 if ($age > $self->{'cobject'}->created_at)
1357 0 0 if ($self->{'logger'})
1367 0 0 if ($self->{'logger'})
1376 0 31 if ($self->{'script_mtime'})
1379 0 31 unless (defined $self->{'info'})
1380 0 0 if ($self->{'cache'}) { }
1388 0 31 unless (defined $path)
1400 2 31 if ($self->{'compress_content'} and $ENV{'HTTP_ACCEPT_ENCODING'} || $ENV{'HTTP_TE'})
1401 2 0 if (defined $self->{'content_type'})
1403 0 2 if ($content_type[0] ne "text")
1407 1 1 $ENV{'HTTP_ACCEPT_ENCODING'} ? :
1409 1 0 if ($method eq "gzip" or $method eq "x-gzip" or $method eq "br")
1424 31 3 if (lc $header_name eq "content-type")
1435 32 0 ref $_[0] eq 'HASH' ? :
1437 0 32 unless defined $self->{'body'}
1440 30 2 if (length $encoding == 0 or length $self->{'body'} < 32)
1444 1 1 if ($encoding eq 'gzip') { }
1 0 elsif ($encoding eq 'br') { }
1449 1 0 unless ($self->{'_encode_loaded'})
1454 0 1 if (length $nbody < length $self->{'body'})
1456 0 0 unless (grep /^Content-Encoding: gzip/, @{$$self{"o"};})
1459 0 0 unless (grep /^Vary: Accept-Encoding/, @{$$self{"o"};})
1467 0 1 unless ($self->{'_encode_loaded'})
1472 1 0 if (length $nbody < length $self->{'body'})
1474 1 0 unless (grep /^Content-Encoding: br/, @{$$self{"o"};})
1477 1 0 unless (grep /^Vary: Accept-Encoding/, @{$$self{"o"};})
1487 0 2 if ($self->{'logger'})
1490 2 0 if ($ENV{'HTTP_IF_NONE_MATCH'} eq $self->{'etag'})
1494 0 2 if ($self->{'logger'})
1499 0 0 if ($self->{'cache'} and $self->{'logger'} and $self->{'logger'}->is_debug)
1502 0 0 if ($cached_copy and $self->{'body'}) { }
1520 0 0 unless $dbh and $self->{'info'} and my $request_uri = $ENV{'REQUEST_URI'}
1521 0 0 unless defined $unzipped_body
1530 0 0 if $seen_links{$link}
1535 0 0 if ($search_uri =~ /^\?/) { }
1542 0 0 if $link =~ m[^https?://]
1544 0 0 if $link =~ /.html?$/
1545 0 0 if $link =~ /.jpg$/
1546 0 0 if $link =~ /.gif$/
1548 0 0 if ($self->{'save_to'}{'ttl'}) { }
1553 0 0 if ($self->{'logger'})
1556 0 0 if (defined(my $sth = $dbh->prepare($query))) { }
0 0 elsif ($self->{'logger'}) { }
1558 0 0 if (my $href = $sth->fetchrow_hashref)
1559 0 0 if (my $path = $href->{'path'})
1560 0 0 if (-r $path) { }
1561 0 0 if ($self->{'logger'})
1569 0 0 if (not defined $creation or $href->{'creation'} < $creation)
1575 0 0 if ($self->{'logger'})
1586 0 0 if (defined $creation and my $ttl = $self->{'save_to'}{'ttl'})
1589 0 0 if ($changes and $expiration == 0 || $expiration >= time) { }
0 0 elsif ($expiration and $expiration < time) { }
1590 0 0 if ($self->{'logger'})
1592 0 0 if ($changes == 1) { }
1593 0 0 if ($self->{'save_to'}{'ttl'}) { }
1604 0 0 if (my $ttl = $self->{'save_to'}{'ttl'})
1609 0 0 if ($self->{'save_to'}{'ttl'}) { }
1617 0 0 if (my $path = $href->{'path'})
1618 0 0 if ($self->{'logger'})
1624 0 0 if ($self->{'save_to'}{'ttl'}) { }
1629 0 0 if ($self->{'logger'})