Branch Coverage

blib/lib/FCGI/Buffer.pm
Criterion Covered Total %
branch 174 524 33.2


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'})
179 1 33 if ($ENV{'REQUEST_METHOD'} and $ENV{'REQUEST_METHOD'} eq 'HEAD') { }
185 34 0 if ($headers)
189 2 32 if (defined $self->{'body'} and $self->{'body'} eq '') { }
29 3 elsif (defined $self->{'content_type'}) { }
193 0 2 if ($self->{'cache'})
199 29 0 if (defined $content_type[0] and lc $content_type[0] eq "text" and lc($content_type[1]) =~ /^html/ and defined $self->{'body'})
200 25 4 if ($self->{'optimise_content'})
204 0 25 if ($self->{'logger'})
211 24 1 if ($self->{'optimise_content'} == 1) { }
217 1 2 if $newlength >= $oldlength
226 22 3 unless (defined $self->{'info'})
227 0 22 if ($self->{'cache'}) { }
237 10 15 unless ($protocol)
248 18 7 if (my $script_name = $ENV{'SCRIPT_NAME'})
249 18 0 if ($script_name =~ m[^/])
275 1 24 if ($self->{'optimise_content'} >= 2)
282 1 24 if ($self->{'optimise_content'} >= 2)
288 1 0 if $newlength >= $oldlength
293 3 26 if ($self->{'lint_content'})
297 0 3 if ($self->{'logger'})
304 1 2 if ($lint->errors)
310 0 3 if ($self->{'logger'}) { }
322 1 33 if (defined $headers and $headers =~ /^Status: (\d+)/m) { }
25 8 elsif (defined $self->{'info'}) { }
330 1 33 if ($self->{'logger'})
337 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'})
342 2 2 if ($ENV{'HTTP_IF_NONE_MATCH'} and $self->{'generate_304'} and $self->{'status'} == 200)
348 0 34 if (my $save_to = $self->{'save_to'})
350 0 0 if ($self->{'logger'})
353 0 0 if (not -r $sqlite_file) { }
354 0 0 unless (-d $save_to->{'directory'})
358 0 0 if ($self->{'save_to'}{'create_table'})
369 32 2 if (defined $unzipped_body)
370 0 32 $ENV{'Range'} ? :
372 3 29 if ($range and not $self->{'cache'})
374 3 0 if ($range =~ /^bytes=(\d*)-(\d*)/)
375 1 2 if ($1 and $2) { }
1 1 elsif ($1) { }
1 0 elsif ($2) { }
389 0 34 if ($self->{'cache'}) { }
26 8 elsif ($self->{'info'}) { }
396 0 0 if (not defined $self->{'body'}) { }
397 0 0 if ($self->{'send_body'})
399 0 0 if (defined $self->{'cobject'}) { }
0 0 elsif ($self->{'logger'}) { }
404 0 0 if ($self->{'info'}) { }
421 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)
424 0 0 if ($ENV{'HTTP_IF_MODIFIED_SINCE'})
431 0 0 if ($self->{'send_body'} and $self->{'status'} == 200 and defined $cache_hash)
433 0 0 if ($dbh)
435 0 0 if ($changes and my $ttl = $self->{'save_to'}{'ttl'})
439 0 0 unless (defined $self->{'body'})
448 0 0 if ($dbh)
451 0 0 if ($self->{'logger'})
454 0 0 if ($sth->execute and my $href = $sth->fetchrow_hashref)
455 0 0 if (my $path = $href->{'path'})
461 0 0 if ($self->{'logger'})
468 0 0 if ($self->{'logger'}) { }
479 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)
482 0 0 if ($ENV{'HTTP_IF_NONE_MATCH'} and $self->{'generate_etag'})
483 0 0 unless (defined $self->{'etag'})
489 0 0 if ($self->{'status'} == 200)
491 0 0 if ($self->{'send_body'})
492 0 0 if ($self->{'generate_etag'} and not defined $self->{'etag'} and not defined $headers && $headers =~ /^ETag: /m)
499 0 0 unless ($self->{'etag'})
500 0 0 if (defined $headers and $headers =~ /^ETag: "([a-z0-9]{32})"/m) { }
506 0 0 if ($ENV{'HTTP_IF_NONE_MATCH'} and $self->{'send_body'} and $self->{'status'} != 304 and $self->{'generate_304'})
507 0 0 unless ($self->_check_if_none_match)
511 0 0 if ($self->{'cobject'})
512 0 0 if ($ENV{'HTTP_IF_MODIFIED_SINCE'} and $self->{'status'} != 304 and not $cannot_304)
518 0 0 if ($self->{'status'} == 200 and $self->{'generate_last_modified'})
519 0 0 if ($self->{'logger'})
527 0 0 if ($self->{'status'} == 200)
530 0 0 unless ($self->{'cache_age'})
537 0 0 if ($changes and $encoding)
540 0 0 if ($self->{'o'} and scalar @{$self->{'o'};}) { }
0 0 elsif (defined $headers and length $headers) { }
544 0 0 if (defined $headers and length $headers) { }
552 0 0 if (length $c)
559 0 0 if (length $headers)
563 0 0 if ($self->{'generate_etag'})
564 0 0 unless (defined $self->{'etag'})
572 0 0 if ($self->{'logger'})
579 0 0 if ($dbh and $self->{'info'} and $self->{'save_to'} and my $request_uri = $ENV{'REQUEST_URI'})
581 0 0 if ($self->{'logger'})
586 0 0 if (my $href = $sth->fetchrow_hashref) { }
587 0 0 if (my $ttl = $self->{'save_to'}{'ttl'})
595 0 0 if ($self->{'lingua'}) { }
597 0 0 if ($language =~ /([\w\s]+)/i)
604 0 0 if ($bdir =~ m(^([/\\])(.+)$))
609 0 0 if ($self->{'logger'})
616 0 0 if ($path =~ /^(.+)$/)
620 0 0 if (open my $fout, '>', $path) { }
632 0 0 unless ($self->{'_encode_loaded'})
641 0 0 if ($self->{'logger'})
646 0 0 if ($changes and my $ttl = $self->{'save_to'}{'ttl'})
650 0 0 if ($self->{'logger'})
656 0 0 if ($self->{'generate_last_modified'})
658 0 0 if (defined $self->{'cobject'}) { }
665 0 0 if ($self->{'info'}) { }
667 0 0 if (defined $self->{'x_cache'}) { }
674 0 0 if (defined $self->{'x_cache'}) { }
689 26 0 if ($self->{'generate_last_modified'})
690 8 18 if (my $age = $self->_my_age)
694 3 0 if ($ENV{'HTTP_IF_MODIFIED_SINCE'} and $self->{'status'} != 304 and $self->{'generate_304'})
700 0 26 if ($self->_save_to($unzipped_body, $dbh) and $encoding)
740 11 23 if ($self->{'generate_etag'} and not defined $headers && $headers =~ /^ETag: /m)
741 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) { }
743 0 11 if ($self->{'logger'})
766 32 2 if (defined $self->{'body'}) { }
767 1 31 if (utf8::is_utf8($self->{'body'}))
775 34 0 if (defined $headers and length $headers) { }
779 30 2 if ($self->{'body'} and $self->{'send_body'})
780 30 0 unless (grep /^Content-Length: \d/, @{$$self{"o"};})
784 31 3 unless (grep /^Status: \d/, @{$$self{"o"};})
794 30 2 if ($body_length and $self->{'send_body'})
799 34 0 if (do {
806 0 0 if ($self->{'logger'})
835 4 30 if (not $self->{'send_body'} && defined $self->{'body'})
843 0 11 if defined $self->{'etag'}
844 0 11 unless defined $self->{'body'}
846 11 0 unless (defined $self->{'_encode_loaded'})
852 0 11 if ($self->{'logger'})
860 0 3 if ($self->{'logger'})
864 0 3 unless ($self->{'generate_304'})
869 0 3 unless (defined $params->{'since'})
873 1 2 unless (defined $s)
874 0 1 if ($self->{'logger'})
881 2 0 unless (defined $age)
882 0 2 if ($self->{'logger'})
887 0 0 if ($age > $s)
888 0 0 if ($self->{'logger'})
895 0 0 if ($self->{'logger'})
898 0 0 if ($params->{'modified'} <= $s)
902 0 0 if ($self->{'logger'})
968 0 0 if ($self->{'cache_key'})
971 0 0 unless (defined $self->{'info'})
977 0 0 if ($self->{'lingua'})
980 0 0 if ($ENV{'HTTP_COOKIE'})
985 0 0 unless ($cookie =~ /^__utm[abcz]/)
993 0 0 if ($headers and $headers =~ /^Vary: .*$/m)
994 0 0 if (defined $self->{'logger'})
999 0 0 if (lc $h1_name eq "vary")
1002 0 0 if ($h2_name eq $h1_value)
1013 0 0 if (defined $self->{'logger'})
1102 22 10 ref $_[0] eq 'HASH' ? :
1105 9 23 if (defined $params{'generate_etag'})
1108 0 32 if (defined $params{'generate_last_modified'})
1111 1 31 if (defined $params{'compress_content'})
1114 31 1 if (defined $params{'optimise_content'})
1117 4 28 if (defined $params{'lint_content'})
1120 1 31 if (defined $params{'logger'})
1123 0 32 if (defined $params{'lingua'})
1127 1 31 if (defined $params{'save_to'} and $self->can_cache) { }
0 62 elsif (exists $params{'save_to'} and not defined $params{'save_to'}) { }
1128 1 0 if (my $dir = $params{'save_to'}{'directory'})
1129 1 0 unless (-d $dir)
1131 1 0 unless (-d $dir)
1136 0 0 unless (-w $dir)
1142 0 0 unless (exists $params{'save_to'}{'ttl'})
1148 3 28 if (defined $params{'generate_304'})
1151 4 27 if (defined $params{'info'} and not defined $self->{'info'})
1157 0 31 if ($pos > 0)
1158 0 0 if (defined $self->{'logger'}) { }
1166 0 31 if (exists $params{'cache'} and $self->can_cache)
1167 0 0 if (defined $ENV{'HTTP_CACHE_CONTROL'})
1169 0 0 if (defined $self->{'logger'})
1172 0 0 if ($control =~ /^max-age\s*=\s*(\d+)$/)
1176 0 0 if (defined $self->{'logger'})
1182 0 0 if (not defined $params{'cache'} and defined $self->{'cache'}) { }
1183 0 0 if (defined $self->{'logger'})
1184 0 0 if ($self->{'cache_key'}) { }
1194 0 0 if (defined $params{'cache_key'})
1206 11 0 unless scalar @_
1219 8 3 ref $_[0] eq 'HASH' ? :
1234 1 8 if (defined $self->{'x_cache'})
1237 0 8 if (defined $ENV{'NO_CACHE'} or defined $ENV{'NO_STORE'})
1241 0 8 if (defined $ENV{'HTTP_CACHE_CONTROL'})
1243 0 0 if (defined $self->{'logger'})
1247 0 0 if ($control eq "no-store" or $control eq "no-cache" or $control eq "max-age=0" or $control eq "private")
1301 12 0 unless ($self->{'cache'})
1302 0 12 if ($self->{'logger'})
1314 0 0 if ($self->{'logger'})
1318 0 0 unless ($self->{'cobject'})
1319 0 0 if ($self->{'logger'})
1324 0 0 unless ($self->{'cobject'}->value($key))
1325 0 0 if ($self->{'logger'})
1335 0 0 unless (defined $age)
1336 0 0 if ($self->{'logger'})
1344 0 0 if ($age > $self->{'cobject'}->created_at)
1346 0 0 if ($self->{'logger'})
1356 0 0 if ($self->{'logger'})
1365 0 31 if ($self->{'script_mtime'})
1368 0 31 unless (defined $self->{'info'})
1369 0 0 if ($self->{'cache'}) { }
1377 0 31 unless (defined $path)
1389 2 31 if ($self->{'compress_content'} and $ENV{'HTTP_ACCEPT_ENCODING'} || $ENV{'HTTP_TE'})
1390 2 0 if (defined $self->{'content_type'})
1392 0 2 if ($content_type[0] ne "text")
1396 1 1 $ENV{'HTTP_ACCEPT_ENCODING'} ? :
1398 1 0 if ($method eq "gzip" or $method eq "x-gzip" or $method eq "br")
1413 31 3 if (lc $header_name eq "content-type")
1424 32 0 ref $_[0] eq 'HASH' ? :
1428 30 2 if (length $encoding == 0 or length $self->{'body'} < 32)
1432 1 1 if ($encoding eq 'gzip') { }
1 0 elsif ($encoding eq 'br') { }
1437 1 0 unless ($self->{'_encode_loaded'})
1442 0 1 if (length $nbody < length $self->{'body'})
1444 0 0 unless (grep /^Content-Encoding: gzip/, @{$$self{"o"};})
1447 0 0 unless (grep /^Vary: Accept-Encoding/, @{$$self{"o"};})
1455 0 1 unless ($self->{'_encode_loaded'})
1460 1 0 if (length $nbody < length $self->{'body'})
1462 1 0 unless (grep /^Content-Encoding: br/, @{$$self{"o"};})
1465 1 0 unless (grep /^Vary: Accept-Encoding/, @{$$self{"o"};})
1475 0 2 if ($self->{'logger'})
1478 2 0 if ($ENV{'HTTP_IF_NONE_MATCH'} eq $self->{'etag'})
1482 0 2 if ($self->{'logger'})
1487 0 0 if ($self->{'cache'} and $self->{'logger'} and $self->{'logger'}->is_debug)
1490 0 0 if ($cached_copy and $self->{'body'}) { }
1508 0 0 unless $dbh and $self->{'info'} and my $request_uri = $ENV{'REQUEST_URI'}
1509 0 0 unless defined $unzipped_body
1518 0 0 if $seen_links{$link}
1523 0 0 if ($search_uri =~ /^\?/) { }
1530 0 0 if $link =~ m[^https?://]
1532 0 0 if $link =~ /.html?$/
1533 0 0 if $link =~ /.jpg$/
1534 0 0 if $link =~ /.gif$/
1536 0 0 if ($self->{'save_to'}{'ttl'}) { }
1541 0 0 if ($self->{'logger'})
1544 0 0 if (defined(my $sth = $dbh->prepare($query))) { }
0 0 elsif ($self->{'logger'}) { }
1546 0 0 if (my $href = $sth->fetchrow_hashref)
1547 0 0 if (my $path = $href->{'path'})
1548 0 0 if (-r $path) { }
1549 0 0 if ($self->{'logger'})
1557 0 0 if (not defined $creation or $href->{'creation'} < $creation)
1563 0 0 if ($self->{'logger'})
1574 0 0 if (defined $creation and my $ttl = $self->{'save_to'}{'ttl'})
1577 0 0 if ($changes and $expiration == 0 || $expiration >= time) { }
0 0 elsif ($expiration and $expiration < time) { }
1578 0 0 if ($self->{'logger'})
1580 0 0 if ($changes == 1) { }
1581 0 0 if ($self->{'save_to'}{'ttl'}) { }
1592 0 0 if (my $ttl = $self->{'save_to'}{'ttl'})
1597 0 0 if ($self->{'save_to'}{'ttl'}) { }
1605 0 0 if (my $path = $href->{'path'})
1606 0 0 if ($self->{'logger'})
1612 0 0 if ($self->{'save_to'}{'ttl'}) { }
1617 0 0 if ($self->{'logger'})