blib/lib/FCGI/Buffer.pm

filter: Statementstmt 59.8% 534 / 892 Branchbran 47.9% 277 / 578 Conditioncond 49.4% 137 / 277 MC/DCmcdc 29.5% 44 / 149 Subroutinesub 96.5% 28 / 29 Podpod 100% 5 / 5 totaltotal 53.1% 1025 / 1930 CC 390 SCAR 74.0
CC
390
Cov
54%
DESTROY
3015.9
_save_to
1523.7
_generate_key
193.6
CRAP 1629.6
↑ Summary
1 package FCGI::Buffer;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # FIXME: save_to treats ?arg1=a&arg2=b and ?arg2=b&arg1=a as different
7 # FIXME: save_to treats /cgi-bin/foo.fcgi and /cgi-bin2/foo.fcgi as the same
8  
9 11 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use IO::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use CGI::Info;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use HTTP::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 11 Readonly my $DEFAULT_GENERATE_304 => 1;
20 11 Readonly my $DEFAULT_GENERATE_LAST_MODIFIED => 1;
21 11 Readonly my $DEFAULT_COMPRESS_CONTENT => 1;
22 11 Readonly my $DEFAULT_OPTIMISE_CONTENT => 0;
23 11 Readonly my $DEFAULT_LINT_CONTENT => 0;
24 11 Readonly my $MIN_GZIP_LEN => 32;
25  
26 =head1 NAME
27  
28 FCGI::Buffer - Verify, Cache and Optimise FCGI Output
29  
30 =head1 VERSION
31  
32 Version 0.21
33  
34 =cut
35  
36 11 our $VERSION = '0.21';
37  
38 =head1 SYNOPSIS
39  
40 FCGI::Buffer verifies the HTML that you produce by passing it through
41 C<HTML::Lint>.
42  
43 FCGI::Buffer optimises FCGI programs by reducing, filtering and compressing
44 output to speed up the transmission and by nearly seamlessly making use of
45 client and server caches.
46  
47 To make use of client caches, that is to say to reduce needless calls
48 to your server asking for the same data:
49  
50 use FCGI;
51 use FCGI::Buffer;
52 # ...
53 my $request = FCGI::Request();
54 while($request->FCGI::Accept() >= 0) {
55 my $buffer = FCGI::Buffer->new();
56 $buffer->init(
57 optimise_content => 1,
58 lint_content => 0,
59 );
60 # ...
61 }
62  
63 To also make use of server caches, that is to say,
64 to save regenerating output when different clients ask you for the same data,
65 you will need to create a cache.
66 But that's simple:
67  
68 use FCGI;
69 use CHI;
70 use FCGI::Buffer;
71  
72 # ...
73 my $request = FCGI::Request();
74 while($request->FCGI::Accept() >= 0) {
75 my $buffer = FCGI::Buffer->new();
76 $buffer->init(
77 optimise_content => 1,
78 lint_content => 0,
79 cache => CHI->new(driver => 'File')
80 );
81 if($buffer->is_cached()) {
82 # Nothing has changed - use the version in the cache
83 $request->Finish();
84 next;
85 # ...
86 }
87 }
88  
89 To temporarily prevent the use of server-side caches, for example, whilst
90 debugging before publishing a code change, set the NO_CACHE environment variable
91 to any non-zero value.
92 This will also stop ETag from being added to the header.
93 If you get errors about Wide characters in print,
94 you've forgotten to emit pure HTML on non-ASCII characters.
95 See L<HTML::Entities>.
96 As a hack work around you could also remove accents and the like by using
97 L<Text::Unidecode>,
98 which works well but isn't really what you want.
99  
100 =head1 SUBROUTINES/METHODS
101  
102 =cut
103  
104 =head2 new
105  
106 Create an FCGI::Buffer object.
107 Do one of these for each FCGI::Accept.
108  
109 =cut
110  
111 # FIXME: Call init() on any arguments that are given
112 sub new
113 {
114 48 ▶ my $proto = shift;
Subroutine new: called CC=9 SCAR=22.5
Pod documented
115 48 ▶ my $class = ref($proto) || $proto;
Condition66%2/3
ref $proto || $proto
l!l&&r!l&&!r
0471
MC/DC50%1/2
ref $proto || $proto
ref $proto $proto
Truth table66%2/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
116  
117 # Use FCGI::Buffer->new(), not FCGI::Buffer::new()
118 48 ▶ if(!defined($class)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $class) 1 47 48
119 1 carp(__PACKAGE__, ': use ->new() not ::new() to instantiate');
120 1 return;
121 }
122  
123 # Handle hash or hashref arguments
124 47 my %args;
125 47 ▶ if((@_ == 1) && (ref $_[0] eq 'HASH')) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 1 46 47
elsif (@_ % 2 == 0) { } 46 0 46
Condition66%2/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
4601
MC/DC50%1/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
126 1 %args = %{$_[0]};
127 } elsif((@_ % 2) == 0) {
128 46 %args = @_;
129 } else {
130 0 carp(__PACKAGE__, ': Invalid arguments passed to new()');
131 0 return;
132 }
133  
134 # Initialize buffer and object properties
135 47 ▶ my $buf = IO::String->new() or croak(__PACKAGE__, ': Failed to initialize IO::String');
Branch: 1 branch
BranchTrueFalseTotal
my $buf = "IO::String"->new or croak(__PACKAGE__, ": Failed to initialize IO::String") 0 47 47
136 47 my $rc = {
137 buf => $buf,
138 old_buf => select($buf),
139 generate_304 => $DEFAULT_GENERATE_304,
140 generate_last_modified => $DEFAULT_GENERATE_LAST_MODIFIED,
141 compress_content => $DEFAULT_COMPRESS_CONTENT,
142 optimise_content => $DEFAULT_OPTIMISE_CONTENT,
143 lint_content => $DEFAULT_LINT_CONTENT,
144 %args,
145 };
146 # $rc->{o} = ();
147  
148 # Set generate_etag based on server protocol
149 47 ▶ $rc->{generate_etag} = ($ENV{'SERVER_PROTOCOL'} || '') =~ /^(HTTP\/1\.1|HTTP\/2\.0)$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($ENV{'SERVER_PROTOCOL'} || '') =~ m[^(HTTP/1\.1|HTTP/2\.0)$] ? : 28 19 47
Condition100%2/2
$ENV{'SERVER_PROTOCOL'} || ''
l!l
2918
MC/DC100%1/1
$ENV{'SERVER_PROTOCOL'} || ''
$ENV{'SERVER_PROTOCOL'}
Truth table100%2/2
A
A= $ENV{'SERVER_PROTOCOL'}
Aresult
11
00
150  
151 # Return the blessed object
152 47 return bless $rc, $class;
153 }
154  
155 sub DESTROY {
156 46 ▶ if(defined($^V) && ($^V ge 'v5.14.0')) {
Subroutine DESTROY: called CC=202 SCAR=80.1
Branch: 1 branch
BranchTrueFalseTotal
if (defined $^V and $^V ge "v5.14.0") 46 0 46
Condition33%1/3
defined $^V and $^V ge "v5.14.0"
!ll&&!rl&&r
0046
MC/DC0%0/2
defined $^V and $^V ge "v5.14.0"
defined $^V $^V ge "v5.14.0"
Truth table33%1/3
A and B
A= defined $^VB= $^V ge "v5.14.0"
ABresult
0X0
100
111
157 46 ▶ return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; # >= 5.14.0 only
Branch: 1 branch
BranchTrueFalseTotal
if ${^GLOBAL_PHASE} eq "DESTRUCT" 0 46 46
158 }
159 46 my $self = shift;
160  
161 46 ▶ if($self->{'logger'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 6 40 46
162 6 $self->{'logger'}->info('In DESTROY');
163 }
164 46 select($self->{old_buf});
165 46 ▶ if((!defined($self->{buf})) || (!defined($self->{buf}->getpos()))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"buf"} and defined $self->{"buf"}->getpos) 0 46 46
Condition33%1/3
defined $self->{"buf"} and defined $self->{"buf"}->getpos
!ll&&!rl&&r
0046
MC/DC0%0/2
defined $self->{"buf"} and defined $self->{"buf"}->getpos
defined $self->{"buf"} defined $self->{"buf"}->getpos
Truth table33%1/3
A and B
A= defined $self->{"buf"}B= defined $self->{"buf"}->getpos
ABresult
0X0
100
111
166 # Unlikely
167 0 ▶ if($self->{'logger'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
168 0 $self->{'logger'}->info('Nothing to send');
169 }
170 0 return;
171 }
172 46 my $pos = $self->{buf}->getpos();
173 46 $self->{buf}->setpos(0);
174 46 my $buf;
175 46 read($self->{buf}, $buf, $pos);
176 46 my $headers;
177 46 ($headers, $self->{body}) = split /\r?\n\r?\n/, $buf, 2;
178  
179 46 ▶ if($self->{'logger'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 6 40 46
180 6 ▶ if($ENV{'HTTP_IF_NONE_MATCH'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_IF_NONE_MATCH"}) 0 6 6
181 0 $self->{logger}->debug("HTTP_IF_NONE_MATCH: $ENV{HTTP_IF_NONE_MATCH}");
182 }
183 6 ▶ if($ENV{'HTTP_IF_MODIFIED_SINCE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_IF_MODIFIED_SINCE"}) 3 3 6
184 3 $self->{logger}->debug("HTTP_IF_MODIFIED_SINCE: $ENV{HTTP_IF_MODIFIED_SINCE}");
185 }
186 6 $self->{logger}->debug("Generate_etag = $self->{generate_etag}, ",
187 "Generate_304 = $self->{generate_304}, ",
188 "Generate_last_modified = $self->{generate_last_modified}");
189 }
190 46 ▶ unless($headers || $self->is_cached()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($headers or $self->is_cached) 3 43 46
Condition100%3/3
$headers or $self->is_cached
l!l&&r!l&&!r
3943
MC/DC100%2/2
$headers or $self->is_cached
$headers $self->is_cached
Truth table100%3/3
A or B
A= $headersB= $self->is_cached
ABresult
1X1
011
000
191 3 ▶ if($self->{'logger'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 3 3
192 0 $self->{'logger'}->debug('There was no output');
193 }
194 3 ▶ if(!defined($headers)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $headers) 3 0 3
195 3 require HTTP::Status;
196 3 HTTP::Status->import();
197  
198 3 ▶ if(!defined($self->{'status'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"status"}) 3 0 3
199 3 ▶ if($self->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'info'}) { } 0 3 3
200 0 $self->{'status'} = $self->{'info'}->status();
201 } else {
202 3 $self->{'status'} = 200;
203 }
204 }
205 print 'Status: ', $self->{status}, ' ',
206 3 HTTP::Status::status_message($self->{status}),
207 "\n\n";
208 }
209 3 return;
210 }
211 43 ▶ if($ENV{'REQUEST_METHOD'} && ($ENV{'REQUEST_METHOD'} eq 'HEAD')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'REQUEST_METHOD'} and $ENV{'REQUEST_METHOD'} eq 'HEAD') { } 1 42 43
Condition100%3/3
$ENV{"REQUEST_METHOD"} and $ENV{"REQUEST_METHOD"} eq "HEAD"
!ll&&!rl&&r
11311
MC/DC100%2/2
$ENV{"REQUEST_METHOD"} and $ENV{"REQUEST_METHOD"} eq "HEAD"
$ENV{"REQUEST_METHOD"} $ENV{"REQUEST_METHOD"} eq "HEAD"
Truth table100%3/3
A and B
A= $ENV{"REQUEST_METHOD"}B= $ENV{"REQUEST_METHOD"} eq "HEAD"
ABresult
0X0
100
111
212 1 $self->{send_body} = 0;
213 } else {
214 42 $self->{send_body} = 1;
215 }
216  
217 43 ▶ if($headers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headers) 39 4 43
218 39 $self->_set_content_type($headers);
219 }
220  
221 43 ▶ if(defined($self->{body}) && ($self->{body} eq '')) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'body'} and $self->{'body'} eq '') { } 3 40 43
elsif (defined $self->{'content_type'}) { } 33 7 40
Condition100%3/3
defined $self->{"body"} and $self->{"body"} eq ""
!ll&&!rl&&r
4363
MC/DC100%2/2
defined $self->{"body"} and $self->{"body"} eq ""
defined $self->{"body"} $self->{"body"} eq ""
Truth table100%3/3
A and B
A= defined $self->{"body"}B= $self->{"body"} eq ""
ABresult
0X0
100
111
222 # E.g. if header of Location is given with no body, for
223 # redirection
224 3 delete $self->{body};
225 3 ▶ if($self->{cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cache"}) 0 3 3
226 # Don't try to retrieve it below from the cache
227 0 $self->{send_body} = 0;
228 }
229 } elsif(defined($self->{content_type})) {
230 33 my @content_type = @{$self->{content_type}};
231 33 ▶ if(defined($content_type[0]) && (lc($content_type[0]) eq 'text') && (lc($content_type[1]) =~ /^html/) && defined($self->{body})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content_type[0] and lc $content_type[0] eq "text" and lc($content_type[1]) =~ /^html/ and defined $self->{"body"}) 33 0 33
Condition33%3/9
defined $content_type[0] and lc $content_type[0] eq "text" and lc($content_type[1]) =~ /^html/ and defined $self->{"body"}
!ll&&!rl&&r
0033
defined $content_type[0] and lc $content_type[0] eq "text" and lc($content_type[1]) =~ /^html/
!ll&&!rl&&r
0033
defined $content_type[0] and lc $content_type[0] eq "text"
!ll&&!rl&&r
0033
MC/DC0%0/4
defined $content_type[0] and lc $content_type[0] eq "text" and lc($content_type[1]) =~ /^html/ and defined $self->{"body"}
defined $content_type[0] lc $content_type[0] eq "text" lc($content_type[1]) =~ /^html/ defined $self->{"body"}
Truth table20%1/5
A and B and C and D
A= defined $content_type[0]B= lc $content_type[0] eq "text"C= lc($content_type[1]) =~ /^html/D= defined $self->{"body"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
232 33 ▶ if($self->{optimise_content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"optimise_content"}) 25 8 33
233 # require HTML::Clean;
234 25 require HTML::Packer; # Overkill using HTML::Clean and HTML::Packer...
235  
236 25 ▶ if($self->{'logger'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 25 25
237 0 $self->{'logger'}->trace('Packer');
238 }
239  
240 25 my $oldlength = length($self->{body});
241 25 my $newlength;
242  
243 25 ▶ if($self->{optimise_content} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'optimise_content'} == 1) { } 24 1 25
244 24 $self->_optimise_content();
245 } else {
246 1 while(1) {
247 3 $self->_optimise_content();
248 3 $newlength = length($self->{body});
249 3 ▶ last if ($newlength >= $oldlength);
Branch: 1 branch
BranchTrueFalseTotal
if $newlength >= $oldlength 1 2 3
250 2 $oldlength = $newlength;
251 }
252 }
253  
254 # If we're on http://www.example.com and have a link
255 # to http://www.example.com/foo/bar.htm, change the
256 # link to /foo/bar.htm - there's no need to include
257 # the site name in the link
258 25 ▶ unless(defined($self->{info})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"info"}) 22 3 25
259 22 ▶ if($self->{cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'cache'}) { } 0 22 22
260 0 $self->{info} = CGI::Info->new({ cache => $self->{cache} });
261 } else {
262 22 $self->{info} = CGI::Info->new();
263 }
264 }
265  
266 25 my $href = $self->{info}->host_name();
267 25 my $protocol = $self->{info}->protocol();
268  
269 25 ▶ unless($protocol) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($protocol) 10 15 25
270 10 $protocol = 'http';
271 }
272  
273 25 $self->{body} =~ s/<a\s+?href="$protocol:\/\/$href"/<a href="\/"/gim;
274 25 $self->{body} =~ s/<a\s+?href="$protocol:\/\/$href/<a href="/gim;
275 25 $self->{body} =~ s/<a\s+?href="$protocol:\/\//<a href="\/\//gim;
276  
277 # If we're in "/cgi-bin/foo.cgi?arg1=a" replace
278 # "/cgi-bin/foo.cgi?arg2=b" with "?arg2=b"
279  
280 25 ▶ if(my $script_name = $ENV{'SCRIPT_NAME'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script_name = $ENV{"SCRIPT_NAME"}) 18 7 25
281 18 ▶ if($script_name =~ /^\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($script_name =~ m[^/]) 18 0 18
282 18 $self->{body} =~ s/<a\s+?href="$script_name(\?.+)?"/<a href="$1"/gim;
283 }
284 }
285  
286 # TODO use URI->path_segments to change links in
287 # /aa/bb/cc/dd.htm which point to /aa/bb/ff.htm to
288 # ../ff.htm
289  
290 # TODO: <img border=0 src=...>
291 25 $self->{body} =~ s/<img\s+?src="$protocol:\/\/$href"/<img src="\/"/gim;
292 25 $self->{body} =~ s/<img\s+?src="$protocol:\/\/$href/<img src="/gim;
293  
294 # Don't use HTML::Clean because of RT402
295 # my $h = new HTML::Clean(\$self->{body});
296 # # $h->compat();
297 # $h->strip();
298 # my $ref = $h->data();
299  
300 # Don't always do javascript 'best' since it's confused
301 # by the common <!-- HIDE technique.
302 25 my $options = {
303 remove_comments => 1,
304 remove_newlines => 0,
305 do_stylesheet => 'minify'
306 };
307 25 ▶ if($self->{optimise_content} >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"optimise_content"} >= 2) 1 24 25
308 1 $options->{do_javascript} = 'best';
309 1 $self->{body} =~ s/(<script.*?>)\s*<!--/$1/gi;
310 1 $self->{body} =~ s/\/\/-->\s*<\/script>/<\/script>/gi;
311 1 $self->{body} =~ s/(<script.*?>)\s+/$1/gi;
312 }
313 25 $self->{body} = HTML::Packer->init()->minify(\$self->{body}, $options);
314 25 ▶ if($self->{optimise_content} >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"optimise_content"} >= 2) 1 24 25
315 # Change document.write("a"); document.write("b")
316 # into document.write("a"+"b");
317 1 while(1) {
318 1 $self->{body} =~ s/<script\s*?type\s*?=\s*?"text\/javascript"\s*?>(.*?)document\.write\((.+?)\);\s*?document\.write\((.+?)\)/<script type="text\/JavaScript">${1}document.write($2+$3)/igs;
319 1 $newlength = length($self->{body});
320 1 ▶ last if ($newlength >= $oldlength);
Branch: 1 branch
BranchTrueFalseTotal
if $newlength >= $oldlength 1 0 1
321 0 $oldlength = $newlength;
322 }
323 }
324 }
325 33 ▶ if($self->{lint_content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lint_content"}) 3 30 33
326 3 require HTML::Lint;
327 3 HTML::Lint->import;
328  
329 3 ▶ if($self->{'logger'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 3 3
330 0 $self->{'logger'}->trace('Lint');
331 }
332 3 my $lint = HTML::Lint->new();
333 3 $lint->parse($self->{body});
334 3 $lint->eof();
335  
336 3 ▶ if($lint->errors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lint->errors) 1 2 3
337 1 $headers = 'Status: 500 Internal Server Error';
338 1 @{$self->{o}} = ('Content-type: text/plain');
339 1 $self->{body} = '';
340 1 foreach my $error ($lint->errors) {
341 3 my $errtext = $error->where() . ': ' . $error->errtext() . "\n";
342 3 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'logger'}) { } 0 3 3
343 0 $self->{logger}->warn($errtext);
344 } else {
345 3 warn($errtext);
346 }
347 3 $self->{body} .= $errtext;
348 }
349 }
350 }
351 }
352 }
353  
354 43 ▶ if(defined($headers) && ($headers =~ /^Status: (\d+)/m)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $headers and $headers =~ /^Status: (\d+)/m) { } 2 41 43
elsif (defined $self->{'info'}) { } 29 12 41
Condition100%3/3
defined $headers and $headers =~ /^Status: (\d+)/m
!ll&&!rl&&r
4372
MC/DC100%2/2
defined $headers and $headers =~ /^Status: (\d+)/m
defined $headers $headers =~ /^Status: (\d+)/m
Truth table100%3/3
A and B
A= defined $headersB= $headers =~ /^Status: (\d+)/m
ABresult
0X0
100
111
355 2 $self->{status} = $1;
356 } elsif(defined($self->{info})) {
357 29 $self->{status} = $self->{info}->status();
358 } else {
359 12 $self->{status} = 200;
360 }
361  
362 43 ▶ if($self->{'logger'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 6 37 43
363 6 $self->{'logger'}->debug("Initial status = $self->{status}");
364 }
365  
366 # Generate the eTag before compressing, since the compressed data
367 # includes the mtime field which changes thus causing a different
368 # Etag to be generated
369 43 ▶ if($ENV{'SERVER_PROTOCOL'} &&
Branch: 1 branch
BranchTrueFalseTotal
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"}) 14 29 43
Condition100%12/12
$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"}
!ll&&!rl&&r
25414
$ENV{"SERVER_PROTOCOL"} and $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" || $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0" and $self->{"generate_etag"}
!ll&&!rl&&r
17818
$ENV{"SERVER_PROTOCOL"} and $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" || $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0"
!ll&&!rl&&r
16126
$ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" or $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0"
l!l&&r!l&&!r
2421
MC/DC100%5/5
$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"}
$ENV{"SERVER_PROTOCOL"} $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0" $self->{"generate_etag"} defined $self->{"body"}
Truth table87%7/8
A and B or C and D and E
A= $ENV{"SERVER_PROTOCOL"}B= $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1"C= $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0"D= $self->{"generate_etag"}E= defined $self->{"body"}
ABCDEresult
0XXXX0
100XX0
11X0X0
1010X0
11X100
101100
11X111
101111
370 (($ENV{'SERVER_PROTOCOL'} eq 'HTTP/1.1') || ($ENV{'SERVER_PROTOCOL'} eq 'HTTP/2.0')) &&
371 $self->{generate_etag} && defined($self->{body})) {
372 14 $self->_generate_etag();
373  
374 14 ▶ if($ENV{'HTTP_IF_NONE_MATCH'} && $self->{generate_304} && ($self->{status} == 200)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_IF_NONE_MATCH"} and $self->{"generate_304"} and $self->{"status"} == 200) 3 11 14
Condition83%5/6
$ENV{"HTTP_IF_NONE_MATCH"} and $self->{"generate_304"} and $self->{"status"} == 200
!ll&&!rl&&r
1103
$ENV{"HTTP_IF_NONE_MATCH"} and $self->{"generate_304"}
!ll&&!rl&&r
923
MC/DC66%2/3
$ENV{"HTTP_IF_NONE_MATCH"} and $self->{"generate_304"} and $self->{"status"} == 200
$ENV{"HTTP_IF_NONE_MATCH"} $self->{"generate_304"} $self->{"status"} == 200
Truth table75%3/4
A and B and C
A= $ENV{"HTTP_IF_NONE_MATCH"}B= $self->{"generate_304"}C= $self->{"status"} == 200
ABCresult
0XX0
10X0
1100
1111
375 3 $self->_check_if_none_match();
376 }
377 }
378  
379 43 my $dbh;
380 43 ▶ if(my $save_to = $self->{save_to}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $save_to = $self->{"save_to"}) 0 43 43
381 0 my $sqlite_file = File::Spec->catfile($save_to->{directory}, 'fcgi.buffer.sql');
382 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
383 0 $self->{logger}->debug("save_to sqlite file: $sqlite_file");
384 }
385 0 ▶ if(!-r $sqlite_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -r $sqlite_file) { } 0 0 0
386 0 ▶ if(!-d $save_to->{directory}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $save_to->{"directory"}) 0 0 0
387 0 mkdir $save_to->{directory};
388 }
389 0 $dbh = DBI->connect("dbi:SQLite:dbname=$sqlite_file", undef, undef);
390 0 ▶ if($self->{save_to}->{create_table}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"save_to"}{"create_table"}) 0 0 0
391 0 $dbh->prepare('CREATE TABLE fcgi_buffer(key char PRIMARY KEY, language char, browser_type char, path char UNIQUE NOT NULL, uri char NOT NULL, creation timestamp NOT NULL)')->execute();
392 }
393 } else {
394 0 $dbh = DBI->connect("dbi:SQLite:dbname=$sqlite_file", undef, undef);
395 }
396 }
397  
398 43 my $encoding = $self->_should_gzip();
399 43 my $unzipped_body = $self->{body};
400  
401 43 ▶ if(defined($unzipped_body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $unzipped_body) 36 7 43
402 36 ▶ my $range = $ENV{'Range'} ? $ENV{'Range'} : $ENV{'HTTP_RANGE'};
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'Range'} ? : 0 36 36
403  
404 36 ▶ if($range && !$self->{cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range and not $self->{"cache"}) 3 33 36
Condition66%2/3
$range and not $self->{"cache"}
!ll&&!rl&&r
3303
MC/DC50%1/2
$range and not $self->{"cache"}
$range not $self->{"cache"}
Truth table66%2/3
A and not(B)
A= $rangeB= not $self->{"cache"}
ABresult
0X0
100
111
405 # TODO: Partials
406 3 ▶ if($range =~ /^bytes=(\d*)-(\d*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range =~ /^bytes=(\d*)-(\d*)/) 3 0 3
407 3 ▶ if($1 && $2) {
Branch: 3 branches
BranchTrueFalseTotal
if ($1 and $2) { } 1 2 3
elsif ($1) { } 1 1 2
elsif ($2) { } 1 0 1
Condition100%3/3
$1 and $2
!ll&&!rl&&r
111
MC/DC100%2/2
$1 and $2
$1 $2
Truth table100%3/3
A and B
A= $1B= $2
ABresult
0X0
100
111
408 1 $self->{body} = substr($self->{body}, $1, $2-$1);
409 } elsif($1) {
410 1 $self->{body} = substr($self->{body}, $1);
411 } elsif($2) {
412 1 $self->{body} = substr($self->{body}, 0, $2);
413 }
414 3 $unzipped_body = $self->{body};
415 3 $self->{'status'} = 206;
416 3 ▶ if($self->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"info"}) 3 0 3
417 3 $self->{'info'}->status(206);
418 }
419 }
420 }
421 36 $self->_compress({ encoding => $encoding });
422 }
423  
424 43 ▶ if($self->{cache}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'cache'}) { } 7 36 43
elsif ($self->{'info'}) { } 26 10 36
425 7 require Storable;
426  
427 7 ▶ if($self->{'cache_age'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cache_age"}) 0 7 7
428 # Legacy
429 0 $self->{'cache_duration'} = $self->{'cache_age'};
430 }
431  
432 7 my $cache_hash;
433 7 my $key = $self->_generate_key();
434  
435 # Cache unzipped version
436 7 ▶ if(!defined($self->{body})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'body'}) { } 4 3 7
437 4 ▶ if($self->{send_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"send_body"}) 4 0 4
438 4 $self->{cobject} = $self->{cache}->get_object($key);
439 4 ▶ if(defined($self->{cobject})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'cobject'}) { } 4 0 4
elsif ($self->{'logger'}) { } 0 0 0
440 4 $cache_hash = Storable::thaw($self->{cobject}->value());
441 4 $headers = $cache_hash->{'headers'};
442 4 $self->_set_content_type($headers);
443 4 @{$self->{o}} = ("X-FCGI-Buffer-$VERSION: Hit");
444 4 ▶ if($self->{info}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'info'}) { } 4 0 4
445 4 my $host_name = $self->{info}->host_name();
446 4 push @{$self->{o}}, "X-Cache: HIT from $host_name", "X-Cache-Lookup: HIT from $host_name";
447 } else {
448 0 push @{$self->{o}}, 'X-Cache: HIT', 'X-Cache-Lookup: HIT';
449 }
450 } elsif($self->{logger}) {
451 0 $self->{logger}->warn("Error retrieving data for key $key");
452 } else {
453 0 carp(__PACKAGE__, ": error retrieving data for key $key");
454 }
455 }
456  
457 # Nothing has been output yet, so we can check if it's
458 # OK to send 304 if possible
459 4 ▶ if($self->{send_body} && $ENV{'SERVER_PROTOCOL'} &&
Branch: 1 branch
BranchTrueFalseTotal
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) 3 1 4
Condition60%9/15
$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
!ll&&!rl&&r
103
$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"}
!ll&&!rl&&r
103
$self->{"send_body"} and $ENV{"SERVER_PROTOCOL"} and $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" || $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0"
!ll&&!rl&&r
103
$self->{"send_body"} and $ENV{"SERVER_PROTOCOL"}
!ll&&!rl&&r
013
$ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" or $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0"
l!l&&r!l&&!r
300
MC/DC16%1/6
$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
$self->{"send_body"} $ENV{"SERVER_PROTOCOL"} $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0" $self->{"generate_304"} $self->{"status"} == 200
Truth table22%2/9
A and B and C or D and E and F
A= $self->{"send_body"}B= $ENV{"SERVER_PROTOCOL"}C= $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1"D= $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0"E= $self->{"generate_304"}F= $self->{"status"} == 200
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X0X0
11010X0
111X100
1101100
111X111
1101111
460 (($ENV{'SERVER_PROTOCOL'} eq 'HTTP/1.1') || ($ENV{'SERVER_PROTOCOL'} eq 'HTTP/2.0')) &&
461 $self->{generate_304} && ($self->{status} == 200)) {
462 3 ▶ if($ENV{'HTTP_IF_MODIFIED_SINCE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_IF_MODIFIED_SINCE"}) 3 0 3
463 $self->_check_modified_since({
464 since => $ENV{'HTTP_IF_MODIFIED_SINCE'},
465 modified => $self->{cobject}->created_at()
466 3 });
467 }
468 }
469 4 ▶ if($self->{send_body} && ($self->{status} == 200) && defined($cache_hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"send_body"} and $self->{"status"} == 200 and defined $cache_hash) 2 2 4
Condition66%4/6
$self->{"send_body"} and $self->{"status"} == 200 and defined $cache_hash
!ll&&!rl&&r
202
$self->{"send_body"} and $self->{"status"} == 200
!ll&&!rl&&r
202
MC/DC33%1/3
$self->{"send_body"} and $self->{"status"} == 200 and defined $cache_hash
$self->{"send_body"} $self->{"status"} == 200 defined $cache_hash
Truth table50%2/4
A and B and C
A= $self->{"send_body"}B= $self->{"status"} == 200C= defined $cache_hash
ABCresult
0XX0
10X0
1100
1111
470 2 $self->{body} = $cache_hash->{'body'};
471 2 ▶ if($dbh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh) 0 2 2
472 0 my $changes = $self->_save_to($self->{body}, $dbh);
473 0 ▶ if($changes && (my $ttl = $self->{save_to}->{ttl})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changes and my $ttl = $self->{"save_to"}{"ttl"}) 0 0 0
Condition0%0/3
$changes and my $ttl = $self->{"save_to"}{"ttl"}
!ll&&!rl&&r
000
MC/DC0%0/2
$changes and my $ttl = $self->{"save_to"}{"ttl"}
$changes my $ttl = $self->{"save_to"}{"ttl"}
Truth table0%0/3
A and B
A= $changesB= my $ttl = $self->{"save_to"}{"ttl"}
ABresult
0X0
100
111
474 0 push @{$self->{o}}, 'Expires: ' . HTTP::Date::time2str(time + $ttl);
475 }
476 }
477 2 ▶ if(!defined($self->{body})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"body"}) 0 2 2
478 # Panic
479 0 $headers = 'Status: 500 Internal Server Error';
480 0 @{$self->{o}} = ('Content-type: text/plain');
481 0 $self->{body} = "Can't retrieve body for key $key, cache_hash contains:\n";
482 0 foreach my $k (keys %{$cache_hash}) {
483 0 $self->{body} .= "\t$k\n";
484 }
485  
486 0 ▶ if($dbh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh) 0 0 0
487 0 my $query = "SELECT DISTINCT path FROM fcgi_buffer WHERE key = '$key'";
488 0 my $sth = $dbh->prepare($query);
489 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
490 0 $self->{logger}->debug($query);
491 }
492 0 ▶ if($sth->execute() && (my $href = $sth->fetchrow_hashref())) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sth->execute and my $href = $sth->fetchrow_hashref) 0 0 0
Condition0%0/3
$sth->execute and my $href = $sth->fetchrow_hashref
!ll&&!rl&&r
000
MC/DC0%0/2
$sth->execute and my $href = $sth->fetchrow_hashref
$sth->execute my $href = $sth->fetchrow_hashref
Truth table0%0/3
A and B
A= $sth->executeB= my $href = $sth->fetchrow_hashref
ABresult
0X0
100
111
493 0 ▶ if(my $path = $href->{'path'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $href->{"path"}) 0 0 0
494 0 unlink($path);
495 }
496 }
497 0 $query = "DELETE FROM fcgi_buffer WHERE key = '$key'";
498 0 $dbh->do($query);
499 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
500 0 $self->{logger}->debug($query);
501 }
502 }
503  
504 0 $self->{cache}->remove($key);
505  
506 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'logger'}) { } 0 0 0
507 0 $self->{logger}->error("Can't retrieve body for key $key");
508 0 $self->{logger}->warn($self->{body});
509 } else {
510 0 carp("Can't retrieve body for key $key");
511 0 warn($self->{body});
512 }
513 0 $self->{send_body} = 0;
514 0 $self->{status} = 500;
515 0 ▶ if($self->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"info"}) 0 0 0
516 0 $self->{'info'}->status(500);
517 }
518 }
519 }
520 4 ▶ if($self->{send_body} && $ENV{'SERVER_PROTOCOL'} &&
Branch: 1 branch
BranchTrueFalseTotal
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) 1 3 4
Condition66%8/12
$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
!ll&&!rl&&r
301
$self->{"send_body"} and $ENV{"SERVER_PROTOCOL"} and $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" || $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0"
!ll&&!rl&&r
301
$self->{"send_body"} and $ENV{"SERVER_PROTOCOL"}
!ll&&!rl&&r
211
$ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" or $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0"
l!l&&r!l&&!r
100
MC/DC40%2/5
$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
$self->{"send_body"} $ENV{"SERVER_PROTOCOL"} $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1" $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0" $self->{"status"} == 200
Truth table42%3/7
A and B and C or D and E
A= $self->{"send_body"}B= $ENV{"SERVER_PROTOCOL"}C= $ENV{"SERVER_PROTOCOL"} eq "HTTP/1.1"D= $ENV{"SERVER_PROTOCOL"} eq "HTTP/2.0"E= $self->{"status"} == 200
ABCDEresult
0XXXX0
10XXX0
1100X0
111X00
110100
111X11
110111
521 (($ENV{'SERVER_PROTOCOL'} eq 'HTTP/1.1') || ($ENV{'SERVER_PROTOCOL'} eq 'HTTP/2.0')) &&
522 ($self->{status} == 200)) {
523 1 ▶ if($ENV{'HTTP_IF_NONE_MATCH'} && $self->{generate_etag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_IF_NONE_MATCH"} and $self->{"generate_etag"}) 0 1 1
Condition33%1/3
$ENV{"HTTP_IF_NONE_MATCH"} and $self->{"generate_etag"}
!ll&&!rl&&r
100
MC/DC0%0/2
$ENV{"HTTP_IF_NONE_MATCH"} and $self->{"generate_etag"}
$ENV{"HTTP_IF_NONE_MATCH"} $self->{"generate_etag"}
Truth table33%1/3
A and B
A= $ENV{"HTTP_IF_NONE_MATCH"}B= $self->{"generate_etag"}
ABresult
0X0
100
111
524 0 ▶ if(!defined($self->{etag})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"etag"}) 0 0 0
525 0 $self->_generate_etag();
526 }
527 0 $self->_check_if_none_match();
528 }
529 }
530 4 ▶ if($self->{status} == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"status"} == 200) 2 2 4
531 2 $encoding = $self->_should_gzip();
532 2 ▶ if($self->{send_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"send_body"}) 2 0 2
533 2 ▶ if($self->{generate_etag} && !defined($self->{etag}) && ((!defined($headers)) || ($headers !~ /^ETag: /m))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"generate_etag"} and not defined $self->{"etag"} and not defined $headers && $headers =~ /^ETag: /m) 1 1 2
Condition55%5/9
$self->{"generate_etag"} and not defined $self->{"etag"} and not defined $headers && $headers =~ /^ETag: /m
!ll&&!rl&&r
101
$self->{"generate_etag"} and not defined $self->{"etag"}
!ll&&!rl&&r
101
defined $headers && $headers =~ /^ETag: /m
!ll&&!rl&&r
010
MC/DC25%1/4
$self->{"generate_etag"} and not defined $self->{"etag"} and not defined $headers && $headers =~ /^ETag: /m
$self->{"generate_etag"} not defined $self->{"etag"} defined $headers $headers =~ /^ETag: /m
Truth table40%2/5
A and not(B) and not(C && D)
A= $self->{"generate_etag"}B= not defined $self->{"etag"}C= defined $headersD= $headers =~ /^ETag: /m
ABCDresult
0XXX0
10XX0
11110
110X1
11101
534 1 $self->_generate_etag();
535 }
536 2 $self->_compress({ encoding => $encoding });
537 }
538 }
539 4 my $cannot_304 = !$self->{generate_304};
540 4 ▶ unless($self->{etag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"etag"}) 3 1 4
541 3 ▶ if(defined($headers) && ($headers =~ /^ETag: "([a-z0-9]{32})"/m)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $headers and $headers =~ /^ETag: "([a-z0-9]{32})"/m) { } 0 3 3
Condition33%1/3
defined $headers and $headers =~ /^ETag: "([a-z0-9]{32})"/m
!ll&&!rl&&r
030
MC/DC0%0/2
defined $headers and $headers =~ /^ETag: "([a-z0-9]{32})"/m
defined $headers $headers =~ /^ETag: "([a-z0-9]{32})"/m
Truth table33%1/3
A and B
A= defined $headersB= $headers =~ /^ETag: "([a-z0-9]{32})"/m
ABresult
0X0
100
111
542 0 $self->{etag} = $1;
543 } else {
544 3 $self->{etag} = $cache_hash->{'etag'};
545 }
546 }
547 4 ▶ if($ENV{'HTTP_IF_NONE_MATCH'} && $self->{send_body} && ($self->{status} != 304) && $self->{generate_304}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_IF_NONE_MATCH"} and $self->{"send_body"} and $self->{"status"} != 304 and $self->{"generate_304"}) 0 4 4
Condition33%3/9
$ENV{"HTTP_IF_NONE_MATCH"} and $self->{"send_body"} and $self->{"status"} != 304 and $self->{"generate_304"}
!ll&&!rl&&r
400
$ENV{"HTTP_IF_NONE_MATCH"} and $self->{"send_body"} and $self->{"status"} != 304
!ll&&!rl&&r
400
$ENV{"HTTP_IF_NONE_MATCH"} and $self->{"send_body"}
!ll&&!rl&&r
400
MC/DC0%0/4
$ENV{"HTTP_IF_NONE_MATCH"} and $self->{"send_body"} and $self->{"status"} != 304 and $self->{"generate_304"}
$ENV{"HTTP_IF_NONE_MATCH"} $self->{"send_body"} $self->{"status"} != 304 $self->{"generate_304"}
Truth table20%1/5
A and B and C and D
A= $ENV{"HTTP_IF_NONE_MATCH"}B= $self->{"send_body"}C= $self->{"status"} != 304D= $self->{"generate_304"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
548 0 ▶ if(!$self->_check_if_none_match()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_check_if_none_match) 0 0 0
549 0 $cannot_304 = 1;
550 }
551 }
552 4 ▶ if($self->{cobject}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cobject"}) 4 0 4
553 4 ▶ if($ENV{'HTTP_IF_MODIFIED_SINCE'} && ($self->{status} != 304) && !$cannot_304) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_IF_MODIFIED_SINCE"} and $self->{"status"} != 304 and not $cannot_304) 1 3 4
Condition83%5/6
$ENV{"HTTP_IF_MODIFIED_SINCE"} and $self->{"status"} != 304 and not $cannot_304
!ll&&!rl&&r
301
$ENV{"HTTP_IF_MODIFIED_SINCE"} and $self->{"status"} != 304
!ll&&!rl&&r
121
MC/DC66%2/3
$ENV{"HTTP_IF_MODIFIED_SINCE"} and $self->{"status"} != 304 and not $cannot_304
$ENV{"HTTP_IF_MODIFIED_SINCE"} $self->{"status"} != 304 not $cannot_304
Truth table75%3/4
A and B and not(C)
A= $ENV{"HTTP_IF_MODIFIED_SINCE"}B= $self->{"status"} != 304C= not $cannot_304
ABCresult
0XX0
10X0
1100
1111
554 $self->_check_modified_since({
555 since => $ENV{'HTTP_IF_MODIFIED_SINCE'},
556 modified => $self->{cobject}->created_at()
557 1 });
558 }
559 4 ▶ if(($self->{status} == 200) && $self->{generate_last_modified}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"status"} == 200 and $self->{"generate_last_modified"}) 2 2 4
Condition66%2/3
$self->{"status"} == 200 and $self->{"generate_last_modified"}
!ll&&!rl&&r
202
MC/DC50%1/2
$self->{"status"} == 200 and $self->{"generate_last_modified"}
$self->{"status"} == 200 $self->{"generate_last_modified"}
Truth table66%2/3
A and B
A= $self->{"status"} == 200B= $self->{"generate_last_modified"}
ABresult
0X0
100
111
560 2 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 2 0 2
561 2 $self->{logger}->debug('Set Last-Modified to ', HTTP::Date::time2str($self->{cobject}->created_at()));
562 }
563 2 push @{$self->{o}}, 'Last-Modified: ' . HTTP::Date::time2str($self->{cobject}->created_at());
564 }
565 }
566 } else {
567 # Not in the server-side cache
568 3 ▶ if($self->{status} == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"status"} == 200) 2 1 3
569 2 my $changes = $self->_save_to($unzipped_body, $dbh);
570  
571 2 ▶ unless($self->{cache_duration}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"cache_duration"}) 2 0 2
572 # It would be great if CHI::set()
573 # allowed the time to be 'lru' for least
574 # recently used.
575 2 $self->{cache_duration} = '10 minutes';
576 }
577 2 $cache_hash->{'body'} = $unzipped_body;
578 2 ▶ if($changes && $encoding) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changes and $encoding) 0 2 2
Condition33%1/3
$changes and $encoding
!ll&&!rl&&r
200
MC/DC0%0/2
$changes and $encoding
$changes $encoding
Truth table33%1/3
A and B
A= $changesB= $encoding
ABresult
0X0
100
111
579 0 $self->_compress({ encoding => $encoding });
580 }
581 2 ▶ if($self->{o} && scalar(@{$self->{o}})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'o'} and scalar @{$self->{'o'};}) { } 0 2 2
elsif (defined $headers and length $headers) { } 2 0 2
Condition50%1/2
$self->{"o"} and scalar @{$self->{"o"};}
!ll
20
MC/DC0%0/1
$self->{"o"} and scalar @{$self->{"o"};}
$self->{"o"}
Truth table50%1/2
A
A= $self->{"o"}
Aresult
00
11
582 # Remember, we're storing the UNzipped
583 # version in the cache
584 0 my $c;
585 0 ▶ if(defined($headers) && length($headers)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $headers and length $headers) { } 0 0 0
Condition0%0/3
defined $headers and length $headers
!ll&&!rl&&r
000
MC/DC0%0/2
defined $headers and length $headers
defined $headers length $headers
Truth table0%0/3
A and B
A= defined $headersB= length $headers
ABresult
0X0
100
111
586 0 $c = "$headers\r\n" . join("\r\n", @{$self->{o}});
587 } else {
588 0 $c = join("\r\n", @{$self->{o}});
589 }
590 0 $c =~ s/^Content-Encoding: .+$//mg;
591 0 $c =~ s/^Vary: Accept-Encoding.*\r?$//mg;
592 0 $c =~ s/\n+/\n/gs;
593 0 ▶ if(length($c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $c) 0 0 0
594 0 $cache_hash->{'headers'} = $c;
595 }
596 ▶ } elsif(defined($headers) && length($headers)) {
Condition33%1/3
defined $headers and length $headers
!ll&&!rl&&r
002
MC/DC0%0/2
defined $headers and length $headers
defined $headers length $headers
Truth table33%1/3
A and B
A= defined $headersB= length $headers
ABresult
0X0
100
111
597 2 $headers =~ s/^Content-Encoding: .+$//mg;
598 2 $headers =~ s/^Vary: Accept-Encoding.*\r?$//mg;
599 2 $headers =~ s/\n+/\n/gs;
600 2 ▶ if(length($headers)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $headers) 2 0 2
601 2 $cache_hash->{'headers'} = $headers;
602 }
603 }
604 2 ▶ if($self->{generate_etag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"generate_etag"}) 2 0 2
605 2 ▶ if(!defined($self->{etag})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"etag"}) 0 2 2
606 0 $self->_generate_etag();
607 }
608 2 $cache_hash->{'etag'} = $self->{etag};
609 }
610 # TODO: Support the Expires header
611 # if($headers !~ /^Expires: /m))) {
612 # }
613 2 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 1 1 2
614 1 $self->{logger}->debug("Store $key in the cache, age = ", $self->{cache_duration}, ' ', length($cache_hash->{'body'}), ' bytes');
615 }
616 2 $self->{cache}->set($key, Storable::freeze($cache_hash), $self->{cache_duration});
617  
618 # Create a static page with the information and link to that in the output
619 # HTML
620 2 ▶ if($dbh && $self->{info} && $self->{save_to} && (my $request_uri = $ENV{'REQUEST_URI'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh and $self->{"info"} and $self->{"save_to"} and my $request_uri = $ENV{"REQUEST_URI"}) 0 2 2
Condition33%3/9
$dbh and $self->{"info"} and $self->{"save_to"} and my $request_uri = $ENV{"REQUEST_URI"}
!ll&&!rl&&r
200
$dbh and $self->{"info"} and $self->{"save_to"}
!ll&&!rl&&r
200
$dbh and $self->{"info"}
!ll&&!rl&&r
200
MC/DC0%0/4
$dbh and $self->{"info"} and $self->{"save_to"} and my $request_uri = $ENV{"REQUEST_URI"}
$dbh $self->{"info"} $self->{"save_to"} my $request_uri = $ENV{"REQUEST_URI"}
Truth table20%1/5
A and B and C and D
A= $dbhB= $self->{"info"}C= $self->{"save_to"}D= my $request_uri = $ENV{"REQUEST_URI"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
621 0 my $query = "SELECT DISTINCT creation FROM fcgi_buffer WHERE key = ?";
622 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
623 0 $self->{logger}->debug("$query: $key");
624 }
625 0 my $sth = $dbh->prepare($query);
626 0 $sth->execute($key);
627 0 ▶ if(my $href = $sth->fetchrow_hashref()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $href = $sth->fetchrow_hashref) { } 0 0 0
628 0 ▶ if(my $ttl = $self->{save_to}->{ttl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ttl = $self->{"save_to"}{"ttl"}) 0 0 0
629 0 push @{$self->{o}}, 'Expires: ' .
630 0 HTTP::Date::time2str($href->{'creation'} + $ttl);
631 }
632 } else {
633 0 my $dir = $self->{save_to}->{directory};
634 0 my $browser_type = $self->{info}->browser_type();
635 0 my $language;
636 0 ▶ if($self->{'lingua'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'lingua'}) { } 0 0 0
637 0 $language = $self->{lingua}->language();
638 0 ▶ if($language =~ /([\w\s]+)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($language =~ /([\w\s]+)/i) 0 0 0
639 0 $language = $1; # Untaint
640 }
641 } else {
642 0 $language = 'default';
643 }
644 0 my $bdir = File::Spec->catfile($dir, $browser_type);
645 0 ▶ if($bdir =~ /^([\/\\])(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bdir =~ m(^([/\\])(.+)$)) 0 0 0
646 0 $bdir = "$1$2"; # Untaint
647 }
648 0 my $ldir = File::Spec->catfile($bdir, $language);
649 0 my $sdir = File::Spec->catfile($ldir, $self->{info}->script_name());
650 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
651 0 $self->{logger}->debug("Create paths to $sdir");
652 }
653 0 File::Path::make_path($sdir);
654 0 my $file = $self->{'info'}->as_string();
655 0 $file =~ tr/\//_/;
656 0 $file =~ s/\s//g;
657 0 my $path = File::Spec->catfile($sdir, "$file.html");
658 0 ▶ if($path =~ /^(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ /^(.+)$/) 0 0 0
659 0 $path = $1; # Untaint
660 0 $path =~ tr/[\|;]/_/;
661 }
662 0 ▶ if(open(my $fout, '>', $path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fout, '>', $path) { } 0 0 0
663 0 my $u = $request_uri;
664 0 $u =~ s/\?/\\?/g;
665 0 $u =~ s/\)/\\)/g;
666 0 my $copy = $unzipped_body;
667 0 my $changes = ($copy =~ s/<a\s+href="$u"/<a href="$path"/gi);
668  
669 # handle <a href="?arg3=4">Call self with different args</a>
670 0 my $script_name = $ENV{'SCRIPT_NAME'};
671 0 $copy =~ s/<a\s+href="(\?.+?)"/<a href="$script_name$1"/gi;
672  
673 # Avoid Wide character
674 0 ▶ unless($self->{_encode_loaded}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_encode_loaded"}) 0 0 0
675 0 require Encode;
676 0 $self->{_encode_loaded} = 1;
677 }
678 0 print $fout Encode::encode_utf8($copy);
679 0 close $fout;
680 # Do INSERT OR REPLACE in case another program has
681 # got in first,
682 0 $query = "INSERT OR REPLACE INTO fcgi_buffer(key, language, browser_type, path, uri, creation) VALUES('$key', '$language', '$browser_type', '$path', '$request_uri', strftime('\%s','now'))";
683 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
684 0 $self->{logger}->debug($query);
685 }
686 0 $dbh->prepare($query)->execute();
687  
688 0 ▶ if($changes && (my $ttl = $self->{save_to}->{ttl})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changes and my $ttl = $self->{"save_to"}{"ttl"}) 0 0 0
Condition0%0/3
$changes and my $ttl = $self->{"save_to"}{"ttl"}
!ll&&!rl&&r
000
MC/DC0%0/2
$changes and my $ttl = $self->{"save_to"}{"ttl"}
$changes my $ttl = $self->{"save_to"}{"ttl"}
Truth table0%0/3
A and B
A= $changesB= my $ttl = $self->{"save_to"}{"ttl"}
ABresult
0X0
100
111
689 0 push @{$self->{o}}, 'Expires: ' . HTTP::Date::time2str(time + $ttl);
690 }
691 } else {
692 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
693 0 $self->{logger}->warn("Can't create $path");
694 }
695 }
696 }
697 }
698 2 ▶ if($self->{generate_last_modified}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"generate_last_modified"}) 2 0 2
699 2 $self->{cobject} = $self->{cache}->get_object($key);
700 2 ▶ if(defined($self->{cobject})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'cobject'}) { } 2 0 2
701 2 push @{$self->{o}}, 'Last-Modified: ' . HTTP::Date::time2str($self->{cobject}->created_at());
702 } else {
703 0 push @{$self->{o}}, 'Last-Modified: ' . HTTP::Date::time2str(time);
704 }
705 }
706 }
707 3 ▶ if($self->{info}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'info'}) { } 0 3 3
708 0 my $host_name = $self->{info}->host_name();
709 0 ▶ if(defined($self->{x_cache})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'x_cache'}) { } 0 0 0
710 0 push @{$self->{o}}, 'X-Cache: ' . $self->{x_cache} . " from $host_name";
711 } else {
712 0 push @{$self->{o}}, "X-Cache: MISS from $host_name";
713 }
714 0 push @{$self->{o}}, "X-Cache-Lookup: MISS from $host_name";
715 } else {
716 3 ▶ if(defined($self->{x_cache})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'x_cache'}) { } 3 0 3
717 3 push @{$self->{o}}, 'X-Cache: ' . $self->{x_cache};
718 } else {
719 0 push @{$self->{o}}, 'X-Cache: MISS';
720 }
721 3 push @{$self->{o}}, 'X-Cache-Lookup: MISS';
722 }
723 3 push @{$self->{o}}, "X-FCGI-Buffer-$VERSION: Miss";
724 }
725 # We don't need it any more, so give Perl a chance to
726 # tidy it up seeing as we're in the destructor
727 7 delete $self->{cache};
728 } elsif($self->{info}) {
729 26 my $host_name = $self->{info}->host_name();
730 26 push @{$self->{o}}, ("X-Cache: MISS from $host_name", "X-Cache-Lookup: MISS from $host_name");
731 26 ▶ if($self->{generate_last_modified}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"generate_last_modified"}) 26 0 26
732 26 ▶ if(my $age = $self->_my_age()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $age = $self->_my_age) 8 18 26
733 8 push @{$self->{o}}, 'Last-Modified: ' . HTTP::Date::time2str($age);
734 }
735 }
736 26 ▶ if($ENV{'HTTP_IF_MODIFIED_SINCE'} && ($self->{status} != 304) && $self->{generate_304}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_IF_MODIFIED_SINCE"} and $self->{"status"} != 304 and $self->{"generate_304"}) 3 23 26
Condition66%4/6
$ENV{"HTTP_IF_MODIFIED_SINCE"} and $self->{"status"} != 304 and $self->{"generate_304"}
!ll&&!rl&&r
2303
$ENV{"HTTP_IF_MODIFIED_SINCE"} and $self->{"status"} != 304
!ll&&!rl&&r
2303
MC/DC33%1/3
$ENV{"HTTP_IF_MODIFIED_SINCE"} and $self->{"status"} != 304 and $self->{"generate_304"}
$ENV{"HTTP_IF_MODIFIED_SINCE"} $self->{"status"} != 304 $self->{"generate_304"}
Truth table50%2/4
A and B and C
A= $ENV{"HTTP_IF_MODIFIED_SINCE"}B= $self->{"status"} != 304C= $self->{"generate_304"}
ABCresult
0XX0
10X0
1100
1111
737 $self->_check_modified_since({
738 3 since => $ENV{'HTTP_IF_MODIFIED_SINCE'},
739 modified => $self->_my_age()
740 });
741 }
742 26 ▶ if($self->_save_to($unzipped_body, $dbh) && $encoding) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_save_to($unzipped_body, $dbh) and $encoding) 0 26 26
Condition33%1/3
$self->_save_to($unzipped_body, $dbh) and $encoding
!ll&&!rl&&r
2600
MC/DC0%0/2
$self->_save_to($unzipped_body, $dbh) and $encoding
$self->_save_to($unzipped_body, $dbh) $encoding
Truth table33%1/3
A and B
A= $self->_save_to($unzipped_body, $dbh)B= $encoding
ABresult
0X0
100
111
743 0 $self->_compress({ encoding => $encoding });
744 }
745 } else {
746 10 push @{$self->{o}}, ('X-Cache: MISS', 'X-Cache-Lookup: MISS');
747 }
748  
749 # if($self->{generate_etag} && ((!defined($headers)) || ($headers !~ /^ETag: /m))) {
750 # if((!defined($self->{etag})) &&
751 # (($self->{status} == 200) || $self->{status} == 304) &&
752 # $self->{body} && (!$ENV{'NO_CACHE'}) &&
753 # !$self->is_cached()) {
754 # unless($self->{_encode_loaded}) {
755 # require Encode;
756 # $self->{_encode_loaded} = 1;
757 # }
758 # $self->{etag} = '"' . Digest::MD5->new->add(Encode::encode_utf8($unzipped_body))->hexdigest() . '"';
759 # }
760 # if(defined($self->{etag})) {
761 # push @{$self->{o}}, "ETag: $self->{etag}";
762 # if($self->{logger}) {
763 # $self->{logger}->debug("Set ETag to $self->{etag}");
764 # }
765 # } else {
766 # open(my $fout, '>>', '/tmp/FCGI-bug');
767 # print $fout "BUG: ETag not generated, status $self->{status}:\n",
768 # "$headers\n",
769 # 'x' x 40, "\n",
770 # # defined($self->{body}) ? $self->{body} : "body is empty\n",
771 # defined($unzipped_body) ? "$unzipped_body\n" : "body is empty\n",
772 # 'x' x 40,
773 # "\n";
774 # print $fout "ENV:\n";
775 # while(my ($key, $value) = each %ENV) {
776 # print $fout "$key = $value\n";
777 # }
778 # close $fout;
779 # $self->{logger}->warn("BUG: ETag not generated, status $self->{status}");
780 # }
781 # }
782 43 ▶ if($self->{generate_etag} && ((!defined($headers)) || ($headers !~ /^ETag: /m))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"generate_etag"} and not defined $headers && $headers =~ /^ETag: /m) 18 25 43
Condition50%3/6
$self->{"generate_etag"} and not defined $headers && $headers =~ /^ETag: /m
!ll&&!rl&&r
25018
defined $headers && $headers =~ /^ETag: /m
!ll&&!rl&&r
0180
MC/DC33%1/3
$self->{"generate_etag"} and not defined $headers && $headers =~ /^ETag: /m
$self->{"generate_etag"} defined $headers $headers =~ /^ETag: /m
Truth table50%2/4
A and not(B && C)
A= $self->{"generate_etag"}B= defined $headersC= $headers =~ /^ETag: /m
ABCresult
0XX0
1110
10X1
1101
783 18 ▶ if(defined($self->{etag})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'etag'}) { } 17 1 18
elsif ($self->{'logger'} and $self->{'status'} == 200 || $self->{'status'} == 304 and $self->{'body'} and not $ENV{'NO_CACHE'} and not $self->is_cached) { } 0 2 2
784 17 push @{$self->{o}}, "ETag: $self->{etag}";
785 17 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 4 13 17
786 4 $self->{logger}->debug("Set ETag to $self->{etag}");
787 }
788 ▶ } elsif($self->{logger} && (($self->{status} == 200) || $self->{status} == 304) && $self->{body} && (!$ENV{'NO_CACHE'}) && !$self->is_cached()) {
Condition26%4/15
$self->{"logger"} and $self->{"status"} == 200 || $self->{"status"} == 304 and $self->{"body"} and not $ENV{"NO_CACHE"} and not $self->is_cached
!ll&&!rl&&r
100
$self->{"logger"} and $self->{"status"} == 200 || $self->{"status"} == 304 and $self->{"body"} and not $ENV{"NO_CACHE"}
!ll&&!rl&&r
100
$self->{"logger"} and $self->{"status"} == 200 || $self->{"status"} == 304 and $self->{"body"}
!ll&&!rl&&r
100
$self->{"logger"} and $self->{"status"} == 200 || $self->{"status"} == 304
!ll&&!rl&&r
100
$self->{"status"} == 200 or $self->{"status"} == 304
l!l&&r!l&&!r
000
MC/DC0%0/6
$self->{"logger"} and $self->{"status"} == 200 || $self->{"status"} == 304 and $self->{"body"} and not $ENV{"NO_CACHE"} and not $self->is_cached
$self->{"logger"} $self->{"status"} == 200 $self->{"status"} == 304 $self->{"body"} not $ENV{"NO_CACHE"} not $self->is_cached
Truth table10%1/10
A and B or C and D and not(E) and not(F)
A= $self->{"logger"}B= $self->{"status"} == 200C= $self->{"status"} == 304D= $self->{"body"}E= not $ENV{"NO_CACHE"}F= not $self->is_cached
ABCDEFresult
0XXXXX0
100XXX0
11X0XX0
1010XX0
11X10X0
10110X0
11X1100
1011100
11X1111
1011111
789 # $self->{logger}->warn("BUG: ETag not generated, status $self->{status}");
790 # open(my $fout, '>>', '/tmp/FCGI-bug');
791 # print $fout "BUG: ETag not generated, status $self->{status}:\n",
792 # $headers,
793 # 'x' x 40,
794 # defined($self->{body}) ? $self->{body} : "body is empty\n",
795 # 'x' x 40,
796 # "\n";
797 # print $fout "ENV:\n";
798 # while(my ($key, $value) = each %ENV) {
799 # print $fout "$key = $value\n;
800 # }
801 # print $fout 'x' x 40, "\n";
802 # close $fout;
803 # $self->{logger}->warn("BUG: ETag not generated, status $self->{status}");
804 }
805 }
806  
807 43 my $body_length;
808 43 ▶ if(defined($self->{body})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'body'}) { } 38 5 43
809 38 ▶ if(utf8::is_utf8($self->{body})) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($self->{"body"})) 1 37 38
810 1 utf8::encode($self->{body});
811 }
812 38 $body_length = length($self->{body});
813 } else {
814 5 $body_length = 0;
815 }
816  
817 43 ▶ if(defined($headers) && length($headers)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $headers and length $headers) { } 42 1 43
Condition66%2/3
defined $headers and length $headers
!ll&&!rl&&r
0142
MC/DC50%1/2
defined $headers and length $headers
defined $headers length $headers
Truth table66%2/3
A and B
A= defined $headersB= length $headers
ABresult
0X0
100
111
818 # Put the original headers first, then those generated within
819 # FCGI::Buffer
820 42 unshift @{$self->{o}}, split(/\r\n/, $headers);
821 42 ▶ if($self->{body} && $self->{send_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"body"} and $self->{"send_body"}) 34 8 42
Condition100%3/3
$self->{"body"} and $self->{"send_body"}
!ll&&!rl&&r
5334
MC/DC100%2/2
$self->{"body"} and $self->{"send_body"}
$self->{"body"} $self->{"send_body"}
Truth table100%3/3
A and B
A= $self->{"body"}B= $self->{"send_body"}
ABresult
0X0
100
111
822 34 ▶ unless(grep(/^Content-Length: \d/, @{$self->{o}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^Content-Length: \d/, @{$$self{"o"};}) 34 0 34
823 34 push @{$self->{o}}, "Content-Length: $body_length";
824 }
825 }
826 42 ▶ unless(grep(/^Status: \d/, @{$self->{o}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^Status: \d/, @{$$self{"o"};}) 35 7 42
827 35 require HTTP::Status;
828 35 HTTP::Status->import();
829  
830 35 push @{$self->{o}}, 'Status: ' . $self->{status} . ' ' . HTTP::Status::status_message($self->{status});
831 35 ▶ if($self->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"info"}) 26 9 35
832 26 $self->{'info'}->status($self->{'status'});
833 }
834 }
835 } else {
836 1 push @{$self->{o}}, "X-FCGI-Buffer-$VERSION: No headers";
837 }
838  
839 43 ▶ if($body_length && $self->{send_body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body_length and $self->{"send_body"}) 34 9 43
Condition100%3/3
$body_length and $self->{"send_body"}
!ll&&!rl&&r
6334
MC/DC100%2/2
$body_length and $self->{"send_body"}
$body_length $self->{"send_body"}
Truth table100%3/3
A and B
A= $body_lengthB= $self->{"send_body"}
ABresult
0X0
100
111
840 34 push @{$self->{o}}, ('', $self->{body});
841 }
842  
843 # XXXXXXXXXXXXXXXXXXXXXXX
844 43 ▶ if(0) {
Branch: 1 branch
BranchTrueFalseTotal
if (do { scalar @{$self->{"o"};} }) 43 0 43
845 # This code helps to debug Wide character prints
846 my $wideCharWarningsIssued = 0;
847 my $widemess;
848 $SIG{__WARN__} = sub {
849 0 ▶ $wideCharWarningsIssued += "@_" =~ /Wide character in .../;
Subroutine __ANON__: not called CC=3 SCAR=24.8
850 0 $widemess = "@_";
851 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
852 0 $self->{logger}->fatal($widemess);
853 0 my $i = 1;
854 0 $self->{logger}->trace('Stack Trace');
855 0 ▶ while((my @call_details = (caller($i++)))) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@call_details) = &CORE::GLOBAL::caller($i++)) 0 0 0
856 0 $self->{logger}->trace($call_details[1], ':', $call_details[2], ' in function ', $call_details[3]);
857 }
858 }
859 0 CORE::warn(@_); # call the builtin warn as usual
860 };
861  
862 if(scalar @{$self->{o}}) {
863 print join("\r\n", @{$self->{o}});
864 if($wideCharWarningsIssued) {
865 my $mess = join("\r\n", @{$self->{o}});
866 $mess =~ /[^\x00-\xFF]/;
867 open(my $fout, '>>', '/tmp/NJH');
868 print $fout "$widemess:\n",
869 $mess,
870 'x' x 40,
871 "\n";
872 close $fout;
873 }
874 }
875 0 } elsif(scalar @{$self->{o}}) {
876 43 print join("\r\n", @{$self->{o}});
877 }
878 # XXXXXXXXXXXXXXXXXXXXXXX
879  
880 43 ▶ if((!$self->{send_body}) || !defined($self->{body})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"send_body"} && defined $self->{"body"}) 8 35 43
Condition100%3/3
$self->{'send_body'} && defined $self->{'body'}
!ll&&!rl&&r
5335
MC/DC100%2/2
$self->{'send_body'} && defined $self->{'body'}
$self->{'send_body'} defined $self->{'body'}
Truth table100%3/3
A && B
A= $self->{'send_body'}B= defined $self->{'body'}
ABresult
0X0
100
111
881 8 print "\r\n\r\n";
882 }
883 }
884  
885 sub _generate_etag {
886 15 ▶ my $self = shift;
Subroutine _generate_etag: called CC=5 SCAR=16.4
887  
888 15 ▶ return if defined($self->{'etag'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"etag"} 0 15 15
889 15 ▶ return unless defined($self->{'body'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"body"} 0 15 15
890  
891 15 ▶ if(!defined($self->{_encode_loaded})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_encode_loaded"}) 15 0 15
892 # encode to avoid "Wide character in subroutine entry"
893 15 require Encode;
894 15 $self->{_encode_loaded} = 1;
895 }
896 15 $self->{etag} = '"' . Digest::MD5->new->add(Encode::encode_utf8($self->{body}))->hexdigest() . '"';
897 15 ▶ if($self->{'logger'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 2 13 15
898 2 $self->{'logger'}->debug('Etag = ', $self->{'etag'});
899 }
900 }
901  
902 sub _check_modified_since {
903 7 ▶ my $self = shift;
Subroutine _check_modified_since: called CC=14 SCAR=27.8
904  
905 7 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 4 3 7
906 4 $self->{logger}->trace('In _check_modified_since');
907 }
908  
909 7 ▶ if(!$self->{generate_304}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"generate_304"}) 0 7 7
910 0 return;
911 }
912 7 my $params = shift;
913  
914 7 ▶ if(!defined($$params{since})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $params->{"since"}) 0 7 7
915 0 return;
916 }
917 7 my $s = HTTP::Date::str2time($$params{since});
918 7 ▶ if(!defined($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $s) 1 6 7
919 1 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 1 1
920 0 $self->{logger}->info("$$params{since} is not a valid date");
921 }
922 1 return;
923 }
924  
925 6 my $age = $self->_my_age();
926 6 ▶ if(!defined($age)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $age) 2 4 6
927 2 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 2 2
928 0 $self->{logger}->info("Can't determine my age");
929 }
930 2 return;
931 }
932 4 ▶ if($age > $s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($age > $s) 2 2 4
933 2 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 2 0 2
934 2 $self->{logger}->debug('_check_modified_since: script has been modified');
935 }
936 # Script has been updated so it may produce different output
937 2 return;
938 }
939  
940 2 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 2 0 2
941 2 $self->{logger}->debug("_check_modified_since: Compare $$params{modified} with $s");
942 }
943 2 ▶ if($$params{modified} <= $s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"modified"} <= $s) 2 0 2
944 2 push @{$self->{o}}, 'Status: 304 Not Modified';
945 2 $self->{status} = 304;
946 2 ▶ if($self->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"info"}) 2 0 2
947 2 $self->{'info'}->status(304);
948 }
949 2 $self->{send_body} = 0;
950 2 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 2 0 2
951 2 $self->{logger}->debug('Set status to 304');
952 }
953 }
954 }
955  
956 # Reduce output, e.g. remove superfluous white-space.
957 sub _optimise_content {
958 27 ▶ my $self = shift;
Subroutine _optimise_content: called CC=1 SCAR=0.0
959  
960 # FIXME: regex bad, HTML parser good
961 # Regexp::List - wow!
962 27 $self->{body} =~ s/(((\s+|\r)\n|\n(\s+|\+)))/\n/g;
963 # $self->{body} =~ s/\r\n/\n/gs;
964 # $self->{body} =~ s/\s+\n/\n/gs;
965 # $self->{body} =~ s/\n+/\n/gs;
966 # $self->{body} =~ s/\n\s+|\s+\n/\n/g;
967 27 $self->{body} =~ s/\<\/div\>\s+\<div/\<\/div\>\<div/gis;
968 # $self->{body} =~ s/\<\/p\>\s\<\/div/\<\/p\>\<\/div/gis;
969 # $self->{body} =~ s/\<div\>\s+/\<div\>/gis; # Remove spaces after <div>
970 27 $self->{body} =~ s/(<div>\s+|\s+<div>)/<div>/gis;
971 27 $self->{body} =~ s/\s+<\/div\>/\<\/div\>/gis; # Remove spaces before </div>
972 27 $self->{body} =~ s/\s+\<p\>|\<p\>\s+/\<p\>/im; # TODO <p class=
973 27 $self->{body} =~ s/\s+\<\/p\>|\<\/p\>\s+/\<\/p\>/gis;
974 27 $self->{body} =~ s/<html>\s+<head>/<html><head>/is;
975 27 $self->{body} =~ s/\s*<\/head>\s+<body>\s*/<\/head><body>/is;
976 27 $self->{body} =~ s/<html>\s+<body>/<html><body>/is;
977 27 $self->{body} =~ s/<body>\s+/<body>/is;
978 27 $self->{body} =~ s/\s+\<\/html/\<\/html/is;
979 27 $self->{body} =~ s/\s+\<\/body/\<\/body/is;
980 27 $self->{body} =~ s/\s(\<.+?\>\s\<.+?\>)/$1/;
981 # $self->{body} =~ s/(\<.+?\>\s\<.+?\>)\s/$1/g;
982 27 $self->{body} =~ s/\<p\>\s/\<p\>/gi;
983 27 $self->{body} =~ s/\<\/p\>\s\<p\>/\<\/p\>\<p\>/gi;
984 27 $self->{body} =~ s/\<\/tr\>\s\<tr\>/\<\/tr\>\<tr\>/gi;
985 27 $self->{body} =~ s/\<\/td\>\s\<\/tr\>/\<\/td\>\<\/tr\>/gi;
986 27 $self->{body} =~ s/\<\/td\>\s*\<td\>/\<\/td\>\<td\>/gis;
987 27 $self->{body} =~ s/\<\/tr\>\s\<\/table\>/\<\/tr\>\<\/table\>/gi;
988 27 $self->{body} =~ s/\<br\s?\/?\>\s?\<p\>/\<p\>/gi;
989 27 $self->{body} =~ s/\<br\>\s+/\<br\>/gi;
990 27 $self->{body} =~ s/\s+\<br/\<br/gi;
991 27 $self->{body} =~ s/\<br\s?\/\>\s/\<br \/\>/gi;
992 27 $self->{body} =~ s/[ \t]+/ /gs; # Remove duplicate space, don't use \s+ it breaks JavaScript
993 27 $self->{body} =~ s/\s\<p\>/\<p\>/gi;
994 27 $self->{body} =~ s/\s\<script/\<script/gi;
995 27 $self->{body} =~ s/(<script>\s|\s<script>)/<script>/gis;
996 27 $self->{body} =~ s/(<\/script>\s|\s<\/script>)/<\/script>/gis;
997 27 $self->{body} =~ s/\<td\>\s/\<td\>/gi;
998 27 $self->{body} =~ s/\s+\<a\shref="(.+?)"\>\s?/ <a href="$1">/gis;
999 27 $self->{body} =~ s/\s?<a\shref=\s"(.+?)"\>/ <a href="$1">/gis;
1000 27 $self->{body} =~ s/\s+<\/a\>\s+/<\/a> /gis;
1001 27 $self->{body} =~ s/(\s?<hr>\s+|\s+<hr>\s?)/<hr>/gis;
1002 # $self->{body} =~ s/\s<hr>/<hr>/gis;
1003 # $self->{body} =~ s/<hr>\s/<hr>/gis;
1004 27 $self->{body} =~ s/<\/li>\s+<li>/<\/li><li>/gis;
1005 27 $self->{body} =~ s/<\/li>\s+<\/ul>/<\/li><\/ul>/gis;
1006 27 $self->{body} =~ s/<ul>\s+<li>/<ul><li>/gis;
1007 27 $self->{body} =~ s/\s+<\/li>/<\/li>/gis;
1008 27 $self->{body} =~ s/\<\/option\>\s+\<option/\<\/option\>\<option/gis;
1009 27 $self->{body} =~ s/<title>\s*(.+?)\s*<\/title>/<title>$1<\/title>/is;
1010 27 $self->{body} =~ s/<\/center>\s+<center>/ /gis;
1011 }
1012  
1013 # Create a key for the cache
1014 sub _generate_key {
1015 24 ▶ my $self = shift;
Subroutine _generate_key: called CC=15 SCAR=52.7
1016 24 ▶ if($self->{cache_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cache_key"}) 24 0 24
1017 24 return $self->{cache_key};
1018 }
1019 0 ▶ unless(defined($self->{info})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"info"}) 0 0 0
1020 0 $self->{info} = CGI::Info->new({ cache => $self->{cache} });
1021 }
1022  
1023 0 my $key = $self->{info}->browser_type() . '::' . $self->{info}->domain_name() . '::' . $self->{info}->script_name() . '::' . $self->{info}->as_string();
1024  
1025 0 ▶ if($self->{lingua}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"lingua"}) 0 0 0
1026 0 $key .= '::' . $self->{lingua}->language();
1027 }
1028 0 ▶ if($ENV{'HTTP_COOKIE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_COOKIE"}) 0 0 0
1029 # Different states of the client are stored in different caches
1030 # Don't put different Google Analytics in different caches, and anyway they
1031 # would be wrong
1032 0 foreach my $cookie(split(/;/, $ENV{'HTTP_COOKIE'})) {
1033 0 ▶ unless($cookie =~ /^__utm[abcz]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cookie =~ /^__utm[abcz]/) 0 0 0
1034 0 $key .= "::$cookie";
1035 }
1036 }
1037 }
1038  
1039 # Honour the Vary headers
1040 0 my $headers = $self->{'headers'};
1041 0 ▶ if($headers && ($headers =~ /^Vary: .*$/m)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headers and $headers =~ /^Vary: .*$/m) 0 0 0
Condition0%0/3
$headers and $headers =~ /^Vary: .*$/m
!ll&&!rl&&r
000
MC/DC0%0/2
$headers and $headers =~ /^Vary: .*$/m
$headers $headers =~ /^Vary: .*$/m
Truth table0%0/3
A and B
A= $headersB= $headers =~ /^Vary: .*$/m
ABresult
0X0
100
111
1042 0 ▶ if(defined($self->{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"logger"}) 0 0 0
1043 0 $self->{logger}->debug('Found Vary header');
1044 }
1045 0 foreach my $h1(split(/\r?\n/, $headers)) {
1046 0 my ($h1_name, $h1_value) = split /\:\s*/, $h1, 2;
1047 0 ▶ if(lc($h1_name) eq 'vary') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $h1_name eq "vary") 0 0 0
1048 0 foreach my $h2(split(/\r?\n/, $headers)) {
1049 0 my ($h2_name, $h2_value) = split /\:\s*/, $h2, 2;
1050 0 ▶ if($h2_name eq $h1_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h2_name eq $h1_value) 0 0 0
1051 0 $key .= "::$h2_value";
1052 0 last;
1053 }
1054 }
1055 }
1056 }
1057 }
1058 0 $key =~ s/\//::/g;
1059 0 $key =~ s/::::/::/g;
1060 0 $key =~ s/::$//;
1061 0 ▶ if(defined($self->{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"logger"}) 0 0 0
1062 0 $self->{logger}->trace("Returning $key");
1063 }
1064 0 $self->{cache_key} = $key;
1065 0 return $key;
1066 }
1067  
1068 =head2 init
1069  
1070 Set various options and override default values.
1071  
1072 # Put this toward the top of your program before you do anything
1073 # By default, generate_tag, generate_304 and compress_content are ON,
1074 # optimise_content and lint_content are OFF. Set optimise_content to 2 to
1075 # do aggressive JavaScript optimisations which may fail.
1076 use FCGI::Buffer;
1077  
1078 my $buffer = FCGI::Buffer->new()->init({
1079 generate_etag => 1, # make good use of client's cache
1080 generate_last_modified => 1, # more use of client's cache
1081 compress_content => 1, # if gzip the output
1082 optimise_content => 0, # optimise your program's HTML, CSS and JavaScript
1083 cache => CHI->new(driver => 'File'), # cache requests
1084 cache_key => 'string', # key for the cache
1085 cache_duration => '10 minutes', # how long to store responses in the cache
1086 logger => $self->{logger},
1087 lint_content => 0, # Pass through HTML::Lint
1088 generate_304 => 1, # When appropriate, generate 304: Not modified
1089 save_to => { directory => '/var/www/htdocs/save_to', ttl => 600, create_table => 1 },
1090 info => CGI::Info->new(),
1091 lingua => CGI::Lingua->new(),
1092 });
1093  
1094 If no cache_key is given, one will be generated which may not be unique.
1095 The cache_key should be a unique value dependent upon the values set by the
1096 browser.
1097  
1098 The cache object will be an object that understands get_object(),
1099 set(), remove() and created_at() messages, such as an L<CHI> object. It is
1100 used as a server-side cache to reduce the need to rerun database accesses.
1101  
1102 Items stay in the server-side cache by default for 10 minutes.
1103 This can be overridden by the cache_control HTTP header in the request, and
1104 the default can be changed by the cache_duration argument to init().
1105  
1106 Save_to is feature which stores output of dynamic pages to your
1107 htdocs tree and replaces future links that point to that page with static links
1108 to avoid going through CGI at all.
1109 Ttl is set to the number of seconds that the static pages are deemed to
1110 be live for, the default is 10 minutes.
1111 If set to 0, the page is live forever.
1112 To enable save_to, a info and lingua arguments must also be given.
1113 It works best when cache is also given.
1114 Only use where output is guaranteed to be the same with a given set of arguments
1115 (the same criteria for enabling generate_304).
1116 You can turn it off on a case by case basis thus:
1117  
1118 my $params = CGI::Info->new()->params();
1119 if($params->{'send_private_email'}) {
1120 $buffer->init('save_to' => undef);
1121 }
1122  
1123 Info is an optional argument to give information about the FCGI environment, e.g.
1124 a L<CGI::Info> object.
1125  
1126 Logger will be an object that understands debug() such as an L<Log::Log4perl>
1127 object.
1128  
1129 To generate a last_modified header, you must give a cache object.
1130  
1131 Init allows a reference of the options to be passed. So both of these work:
1132 use FCGI::Buffer;
1133 #...
1134 my $buffer = FCGI::Buffer->new();
1135 $b->init(generate_etag => 1);
1136 $b->init({ generate_etag => 1, info => CGI::Info->new() });
1137  
1138 Generally speaking, passing by reference is better since it copies less on to
1139 the stack.
1140  
1141 If you give a cache to init() then later give cache => undef,
1142 the server-side cache is no longer used.
1143 This is useful when you find an error condition when creating your HTML
1144 and decide that you no longer wish to store the output in the cache.
1145  
1146 =cut
1147  
1148 sub init {
1149 41 ▶ my $self = shift;
Subroutine init: called CC=35 SCAR=46.2
Pod documented
1150 41 ▶ my %params = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 29 12 41
1151  
1152 # Safe options - can be called at any time
1153 41 ▶ if(defined($params{generate_etag})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"generate_etag"}) 9 32 41
1154 9 $self->{generate_etag} = $params{generate_etag};
1155 }
1156 41 ▶ if(defined($params{generate_last_modified})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"generate_last_modified"}) 0 41 41
1157 0 $self->{generate_last_modified} = $params{generate_last_modified};
1158 }
1159 41 ▶ if(defined($params{compress_content})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"compress_content"}) 1 40 41
1160 1 $self->{compress_content} = $params{compress_content};
1161 }
1162 41 ▶ if(defined($params{optimise_content})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"optimise_content"}) 31 10 41
1163 31 $self->{optimise_content} = $params{optimise_content};
1164 }
1165 41 ▶ if(defined($params{lint_content})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"lint_content"}) 4 37 41
1166 4 $self->{lint_content} = $params{lint_content};
1167 }
1168 41 ▶ if(defined($params{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"logger"}) 6 35 41
1169 6 $self->{logger} = $params{logger};
1170 }
1171 41 ▶ if(defined($params{lingua})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"lingua"}) 0 41 41
1172 0 $self->{lingua} = $params{lingua};
1173 }
1174  
1175 41 ▶ if(defined($params{save_to}) && $self->can_cache()) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $params{'save_to'} and $self->can_cache) { } 2 39 41
elsif (exists $params{'save_to'} and not defined $params{'save_to'}) { } 0 78 78
Condition66%2/3
defined $params{"save_to"} and $self->can_cache
!ll&&!rl&&r
3902
MC/DC50%1/2
defined $params{"save_to"} and $self->can_cache
defined $params{"save_to"} $self->can_cache
Truth table66%2/3
A and B
A= defined $params{"save_to"}B= $self->can_cache
ABresult
0X0
100
111
1176 2 ▶ if(my $dir = $params{'save_to'}->{'directory'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dir = $params{"save_to"}{"directory"}) 2 0 2
1177 2 ▶ if(! -d $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 1 1 2
1178 1 mkdir $dir;
1179 1 ▶ if(! -d $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 1 0 1
1180 1 Carp::carp("$dir isn't a directory");
1181 1 return;
1182 }
1183 }
1184 1 ▶ if(! -w $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-w $dir) 1 0 1
1185 1 Carp::carp("$dir isn't writeable");
1186 1 return;
1187 }
1188 }
1189 0 $self->{save_to} = $params{save_to};
1190 0 ▶ if(!exists($params{save_to}->{'ttl'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $params{"save_to"}{"ttl"}) 0 0 0
1191 0 $self->{save_to}->{'ttl'} = 600;
1192 }
1193 ▶ } elsif(exists($params{'save_to'}) && !defined($params{'save_to'})) {
Condition33%1/3
exists $params{"save_to"} and not defined $params{"save_to"}
!ll&&!rl&&r
3900
MC/DC0%0/2
exists $params{"save_to"} and not defined $params{"save_to"}
exists $params{"save_to"} not defined $params{"save_to"}
Truth table33%1/3
A and not(B)
A= exists $params{"save_to"}B= not defined $params{"save_to"}
ABresult
0X0
100
111
1194 0 delete $self->{'save_to'};
1195 }
1196 39 ▶ if(defined($params{generate_304})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"generate_304"}) 3 36 39
1197 3 $self->{generate_304} = $params{generate_304};
1198 }
1199 39 ▶ if(defined($params{info}) && (!defined($self->{info}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"info"} and not defined $self->{"info"}) 4 35 39
Condition66%2/3
defined $params{"info"} and not defined $self->{"info"}
!ll&&!rl&&r
3504
MC/DC50%1/2
defined $params{"info"} and not defined $self->{"info"}
defined $params{"info"} not defined $self->{"info"}
Truth table66%2/3
A and not(B)
A= defined $params{"info"}B= not defined $self->{"info"}
ABresult
0X0
100
111
1200 4 $self->{info} = $params{info};
1201 }
1202  
1203 # Unsafe options - must be called before output has been started
1204 39 my $pos = $self->{buf}->getpos;
1205 39 ▶ if($pos > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos > 0) 1 38 39
1206 1 ▶ if(defined($self->{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'logger'}) { } 0 1 1
1207 0 my @call_details = caller(0);
1208 0 $self->{logger}->warn("Too late to call init, $pos characters have been printed, caller line $call_details[2] of $call_details[1]");
1209 } else {
1210 # Must do Carp::carp instead of carp for Test::Carp
1211 1 Carp::carp "Too late to call init, $pos characters have been printed";
1212 }
1213 }
1214 39 ▶ if(exists($params{cache}) && $self->can_cache()) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"cache"} and $self->can_cache) 8 31 39
Condition66%2/3
exists $params{"cache"} and $self->can_cache
!ll&&!rl&&r
3108
MC/DC50%1/2
exists $params{"cache"} and $self->can_cache
exists $params{"cache"} $self->can_cache
Truth table66%2/3
A and B
A= exists $params{"cache"}B= $self->can_cache
ABresult
0X0
100
111
1215 8 ▶ if(defined($ENV{'HTTP_CACHE_CONTROL'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"HTTP_CACHE_CONTROL"}) 0 8 8
1216 0 my $control = $ENV{'HTTP_CACHE_CONTROL'};
1217 0 ▶ if(defined($self->{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"logger"}) 0 0 0
1218 0 $self->{logger}->debug("cache_control = $control");
1219 }
1220 0 ▶ if($control =~ /^max-age\s*=\s*(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($control =~ /^max-age\s*=\s*(\d+)$/) 0 0 0
1221 # There is an argument not to do this
1222 # since one client will affect others
1223 0 $self->{cache_duration} = "$1 seconds";
1224 0 ▶ if(defined($self->{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"logger"}) 0 0 0
1225 0 $self->{logger}->debug("cache_duration = $self->{cache_duration}");
1226 }
1227 }
1228 }
1229 8 ▶ $self->{cache_duration} ||= $params{cache_duration};
Condition33%1/3
$self->{"cache_duration"} ||= $params{"cache_duration"}
l!l&&r!l&&!r
008
MC/DC0%0/2
$self->{"cache_duration"} ||= $params{"cache_duration"}
$self->{"cache_duration"} $params{"cache_duration"}
Truth table33%1/3
A ||= B
A= $self->{"cache_duration"}B= $params{"cache_duration"}
ABresult
1X1
011
000
1230 8 ▶ if((!defined($params{cache})) && defined($self->{cache})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $params{'cache'} and defined $self->{'cache'}) { } 0 8 8
Condition33%1/3
not defined $params{"cache"} and defined $self->{"cache"}
!ll&&!rl&&r
800
MC/DC0%0/2
not defined $params{"cache"} and defined $self->{"cache"}
not defined $params{"cache"} defined $self->{"cache"}
Truth table33%1/3
not(A) and B
A= not defined $params{"cache"}B= defined $self->{"cache"}
ABresult
0X0
100
111
1231 0 ▶ if(defined($self->{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"logger"}) 0 0 0
1232 0 ▶ if($self->{cache_key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'cache_key'}) { } 0 0 0
1233 0 $self->{logger}->debug('disabling cache ', $self->{cache_key});
1234 } else {
1235 0 $self->{logger}->debug('disabling cache');
1236 }
1237 }
1238 0 delete $self->{cache};
1239 } else {
1240 8 $self->{cache} = $params{cache};
1241 }
1242 8 ▶ if(defined($params{cache_key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params{"cache_key"}) 8 0 8
1243 8 $self->{cache_key} = $params{cache_key};
1244 }
1245 }
1246  
1247 39 return $self;
1248 }
1249  
1250 sub import {
1251 # my $class = shift;
1252 10 ▶ shift;
Subroutine import: called CC=2 SCAR=8.1
1253  
1254 10 ▶ return unless scalar(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 10 0 10
1255  
1256 0 init(@_);
1257 }
1258  
1259 =head2 set_options
1260  
1261 Synonym for init, kept for historical reasons.
1262  
1263 =cut
1264  
1265 sub set_options {
1266 11 ▶ my $self = shift;
Subroutine set_options: called CC=2 SCAR=6.9
Pod documented
1267 11 ▶ my %params = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 8 3 11
1268  
1269 11 $self->init(\%params);
1270 }
1271  
1272 =head2 can_cache
1273  
1274 Returns true if the server is allowed to store the results locally.
1275 This is the value of X-Cache in the returned header.
1276  
1277 =cut
1278  
1279 sub can_cache {
1280 25 ▶ my $self = shift;
Subroutine can_cache: called CC=10 SCAR=37.1
Pod documented
1281  
1282 25 ▶ if(defined($self->{x_cache})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"x_cache"}) 10 15 25
1283 10 return ($self->{x_cache} eq 'HIT');
1284 }
1285 15 ▶ if(defined($ENV{'NO_CACHE'}) || defined($ENV{'NO_STORE'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"NO_CACHE"} or defined $ENV{"NO_STORE"}) 0 15 15
Condition33%1/3
defined $ENV{"NO_CACHE"} or defined $ENV{"NO_STORE"}
l!l&&r!l&&!r
0015
MC/DC0%0/2
defined $ENV{"NO_CACHE"} or defined $ENV{"NO_STORE"}
defined $ENV{"NO_CACHE"} defined $ENV{"NO_STORE"}
Truth table33%1/3
A or B
A= defined $ENV{"NO_CACHE"}B= defined $ENV{"NO_STORE"}
ABresult
1X1
011
000
1286 0 $self->{x_cache} = 'MISS';
1287 0 return 0;
1288 }
1289 15 ▶ if(defined($ENV{'HTTP_CACHE_CONTROL'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"HTTP_CACHE_CONTROL"}) 0 15 15
1290 0 my $control = $ENV{'HTTP_CACHE_CONTROL'};
1291 0 ▶ if(defined($self->{logger})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"logger"}) 0 0 0
1292 0 $self->{logger}->debug("cache_control = $control");
1293 }
1294 # TODO: check Authorization header not present
1295 0 ▶ if(($control eq 'no-store') ||
Branch: 1 branch
BranchTrueFalseTotal
if ($control eq "no-store" or $control eq "no-cache" or $control eq "max-age=0" or $control eq "private") 0 0 0
Condition0%0/9
$control eq "no-store" or $control eq "no-cache" or $control eq "max-age=0" or $control eq "private"
l!l&&r!l&&!r
000
$control eq "no-store" or $control eq "no-cache" or $control eq "max-age=0"
l!l&&r!l&&!r
000
$control eq "no-store" or $control eq "no-cache"
l!l&&r!l&&!r
000
MC/DC0%0/4
$control eq "no-store" or $control eq "no-cache" or $control eq "max-age=0" or $control eq "private"
$control eq "no-store" $control eq "no-cache" $control eq "max-age=0" $control eq "private"
Truth table0%0/5
A or B or C or D
A= $control eq "no-store"B= $control eq "no-cache"C= $control eq "max-age=0"D= $control eq "private"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1296 ($control eq 'no-cache') ||
1297 ($control eq 'max-age=0') ||
1298 ($control eq 'private')) {
1299 0 $self->{x_cache} = 'MISS';
1300 0 return 0;
1301 }
1302 }
1303 15 $self->{x_cache} = 'HIT';
1304 15 return 1;
1305 }
1306  
1307 =head2 is_cached
1308  
1309 Returns true if the output is cached. If it is then it means that all of the
1310 expensive routines in the FCGI script can be by-passed because we already have
1311 the result stored in the cache.
1312  
1313 # Put this toward the top of your program before you do anything
1314  
1315 # Example key generation - use whatever you want as something
1316 # unique for this call, so that subsequent calls with the same
1317 # values match something in the cache
1318 use CGI::Info;
1319 use CGI::Lingua;
1320 use FCGI::Buffer;
1321  
1322 my $i = CGI::Info->new();
1323 my $l = CGI::Lingua->new(supported => ['en']);
1324  
1325 # To use server-side caching you must give the cache argument, however
1326 # the cache_key argument is optional - if you don't give one then one will
1327 # be generated for you
1328 my $buffer = FCGI::Buffer->new();
1329 if($buffer->can_cache()) {
1330 $buffer->init(
1331 cache => CHI->new(driver => 'File'),
1332 cache_key => $i->domain_name() . '/' . $i->script_name() . '/' . $i->as_string() . '/' . $l->language()
1333 );
1334 if($buffer->is_cached()) {
1335 # Output will be retrieved from the cache and sent automatically
1336 exit;
1337 }
1338 }
1339 # Not in the cache, so now do our expensive computing to generate the
1340 # results
1341 print "Content-type: text/html\n";
1342 # ...
1343  
1344 =cut
1345  
1346 sub is_cached {
1347 35 ▶ my $self = shift;
Subroutine is_cached: called CC=14 SCAR=35.6
Pod documented
1348  
1349 35 ▶ unless($self->{cache}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"cache"}) 18 17 35
1350 18 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 18 18
1351 0 $self->{logger}->debug("is_cached: cache hasn't been enabled");
1352 0 my $i = 0;
1353 0 ▶ while((my @call_details = (caller($i++)))) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@call_details) = &CORE::GLOBAL::caller($i++)) 0 0 0
1354 0 $self->{logger}->debug($call_details[1], ':', $call_details[2], ' calling function ', $call_details[3]);
1355 }
1356 }
1357 18 return 0;
1358 }
1359  
1360 17 my $key = $self->_generate_key();
1361  
1362 17 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 14 3 17
1363 14 $self->{logger}->debug("is_cached: looking for key = $key");
1364 }
1365 17 $self->{cobject} = $self->{cache}->get_object($key);
1366 17 ▶ unless($self->{cobject}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"cobject"}) 6 11 17
1367 6 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 3 3 6
1368 3 $self->{logger}->debug('not found in cache');
1369 }
1370 6 return 0;
1371 }
1372 11 ▶ unless($self->{cobject}->value($key)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"cobject"}->value($key)) 0 11 11
1373 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
1374 0 $self->{logger}->warn('is_cached: object is in the cache but not the data');
1375 }
1376 0 delete $self->{cobject};
1377 0 return 0;
1378 }
1379  
1380 # If the script has changed, don't use the cache since we may produce
1381 # different output
1382 11 my $age = $self->_my_age();
1383 11 ▶ unless(defined($age)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $age) 0 11 11
1384 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
1385 0 $self->{logger}->debug("Can't determine script's age");
1386 }
1387 # Can't determine the age. Play it safe an assume we're not
1388 # cached
1389 0 delete $self->{cobject};
1390 0 return 0;
1391 }
1392 11 ▶ if($age > $self->{cobject}->created_at()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($age > $self->{"cobject"}->created_at) 0 11 11
1393 # Script has been updated so it may produce different output
1394 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
1395 0 $self->{logger}->debug('Script has been updated');
1396 }
1397 0 delete $self->{cobject};
1398 # Nothing will be in date and all new searches would miss
1399 # anyway, so may as well clear it all
1400 # FIXME: RT104471
1401 # $self->{cache}->clear();
1402 0 return 0;
1403 }
1404 11 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 11 0 11
1405 11 $self->{logger}->debug('Script is in the cache');
1406 }
1407 11 return 1;
1408 }
1409  
1410 # Determine the last modification time of the script and cache it for subsequent calls
1411 sub _my_age {
1412 46 ▶ my $self = shift;
Subroutine _my_age: called CC=7 SCAR=21.3
1413  
1414 46 ▶ if($self->{script_mtime}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"script_mtime"}) 11 35 46
1415 11 return $self->{script_mtime};
1416 }
1417 35 ▶ unless(defined($self->{info})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"info"}) 4 31 35
1418 4 ▶ if($self->{cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'cache'}) { } 4 0 4
1419 $self->{info} = CGI::Info->new({ cache => $self->{cache} })
1420 4 ▶ or croak 'Failed to create CGI::Info object with cache';
Branch: 1 branch
BranchTrueFalseTotal
$self->{"info"} = "CGI::Info"->new({"cache", $self->{"cache"}}) or croak("Failed to create CGI::Info object with cache") 0 4 4
1421 } else {
1422 0 ▶ $self->{info} = CGI::Info->new()
Branch: 1 branch
BranchTrueFalseTotal
$self->{"info"} = "CGI::Info"->new or croak("Failed to create CGI::Info object") 0 0 0
1423 or croak 'Failed to create CGI::Info object';
1424 }
1425 }
1426  
1427 35 my $path = $self->{info}->script_path();
1428 35 ▶ unless(defined($path)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 0 35 35
1429 0 croak 'Failed to retrieve script path';
1430 0 return;
1431 }
1432  
1433 35 my @statb = stat($path);
1434 35 $self->{'script_mtime'} = $statb[9]; # Set script_mtime to the modification time of the script
1435 35 return $self->{script_mtime};
1436 }
1437  
1438 sub _should_gzip {
1439 45 ▶ my $self = shift;
Subroutine _should_gzip: called CC=12 SCAR=26.0
1440  
1441 45 ▶ if($self->{compress_content} && ($ENV{'HTTP_ACCEPT_ENCODING'} || $ENV{'HTTP_TE'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"compress_content"} and $ENV{"HTTP_ACCEPT_ENCODING"} || $ENV{"HTTP_TE"}) 2 43 45
Condition100%6/6
$self->{"compress_content"} and $ENV{"HTTP_ACCEPT_ENCODING"} || $ENV{"HTTP_TE"}
!ll&&!rl&&r
1422
$ENV{"HTTP_ACCEPT_ENCODING"} or $ENV{"HTTP_TE"}
l!l&&r!l&&!r
1142
MC/DC66%2/3
$self->{"compress_content"} and $ENV{"HTTP_ACCEPT_ENCODING"} || $ENV{"HTTP_TE"}
$self->{"compress_content"} $ENV{"HTTP_ACCEPT_ENCODING"} $ENV{"HTTP_TE"}
Truth table75%3/4
A and B or C
A= $self->{"compress_content"}B= $ENV{"HTTP_ACCEPT_ENCODING"}C= $ENV{"HTTP_TE"}
ABCresult
0XX0
1000
11X1
1011
1442 2 ▶ if(defined($self->{content_type})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"content_type"}) 2 0 2
1443 2 my @content_type = @{$self->{content_type}};
1444 2 ▶ if($content_type[0] ne 'text') {
Branch: 1 branch
BranchTrueFalseTotal
if ($content_type[0] ne "text") 0 2 2
1445 0 return '';
1446 }
1447 }
1448 2 ▶ my $accept = lc($ENV{'HTTP_ACCEPT_ENCODING'} ? $ENV{'HTTP_ACCEPT_ENCODING'} : $ENV{'HTTP_TE'});
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'HTTP_ACCEPT_ENCODING'} ? : 1 1 2
1449 2 foreach my $method(split(/,\s?/, $accept)) {
1450 2 ▶ if(($method eq 'gzip') || ($method eq 'x-gzip') || ($method eq 'br') || ($method eq 'zstd')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "gzip" or $method eq "x-gzip" or $method eq "br" or $method eq "zstd") 1 0 1
Condition55%5/9
$method eq "gzip" or $method eq "x-gzip" or $method eq "br" or $method eq "zstd"
l!l&&r!l&&!r
200
$method eq "gzip" or $method eq "x-gzip" or $method eq "br"
l!l&&r!l&&!r
110
$method eq "gzip" or $method eq "x-gzip"
l!l&&r!l&&!r
101
MC/DC0%0/4
$method eq "gzip" or $method eq "x-gzip" or $method eq "br" or $method eq "zstd"
$method eq "gzip" $method eq "x-gzip" $method eq "br" $method eq "zstd"
Truth table40%2/5
A or B or C or D
A= $method eq "gzip"B= $method eq "x-gzip"C= $method eq "br"D= $method eq "zstd"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1451 2 return $method;
1452 }
1453 }
1454 }
1455  
1456 43 return '';
1457 }
1458  
1459 sub _set_content_type {
1460 43 ▶ my $self = shift;
Subroutine _set_content_type: called CC=3 SCAR=11.0
1461 43 my $headers = shift;
1462  
1463 43 foreach my $header (split(/\r?\n/, $headers)) {
1464 42 my ($header_name, $header_value) = split /\:\s*/, $header, 2;
1465 42 ▶ if (lc($header_name) eq 'content-type') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $header_name eq "content-type") 38 4 42
1466 38 my @content_type = split /\//, $header_value, 2;
1467 38 $self->{content_type} = \@content_type;
1468 38 return;
1469 }
1470 }
1471 }
1472  
1473 sub _compress()
1474 {
1475 38 ▶ my $self = shift;
Subroutine _compress: called CC=23 SCAR=47.4
1476 38 ▶ my %params = (ref($_[0]) eq 'HASH') ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 38 0 38
1477  
1478 38 ▶ return unless(defined($self->{'body'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"body"} 0 38 38
1479 38 my $encoding = $params{encoding};
1480  
1481 38 ▶ if((length($encoding) == 0) || (length($self->{body}) < $MIN_GZIP_LEN)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $encoding == 0 or length $self->{"body"} < $MIN_GZIP_LEN) 36 2 38
Condition66%2/3
length $encoding == 0 or length $self->{"body"} < $MIN_GZIP_LEN
l!l&&r!l&&!r
3602
MC/DC50%1/2
length $encoding == 0 or length $self->{"body"} < $MIN_GZIP_LEN
length $encoding == 0 length $self->{"body"} < $MIN_GZIP_LEN
Truth table66%2/3
A or B
A= length $encoding == 0B= length $self->{"body"} < $MIN_GZIP_LEN
ABresult
1X1
011
000
1482 36 return;
1483 }
1484  
1485 2 ▶ if($encoding eq 'gzip') {
Branch: 3 branches
BranchTrueFalseTotal
if ($encoding eq 'gzip') { } 1 1 2
elsif ($encoding eq 'zstd') { } 0 1 1
elsif ($encoding eq 'br') { } 1 0 1
1486 1 require Compress::Zlib;
1487 1 Compress::Zlib->import;
1488  
1489 # Avoid 'Wide character in memGzip'
1490 1 ▶ unless($self->{_encode_loaded}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_encode_loaded"}) 1 0 1
1491 1 require Encode;
1492 1 $self->{_encode_loaded} = 1;
1493 }
1494 1 my $nbody = Compress::Zlib::memGzip(\Encode::encode_utf8($self->{body}));
1495 1 ▶ if(length($nbody) < length($self->{body})) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $nbody < length $self->{"body"}) 0 1 1
1496 0 $self->{body} = $nbody;
1497 0 ▶ unless(grep(/^Content-Encoding: gzip/, @{$self->{o}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^Content-Encoding: gzip/, @{$$self{"o"};}) 0 0 0
1498 0 push @{$self->{o}}, 'Content-Encoding: gzip';
1499 }
1500 0 ▶ unless(grep(/^Vary: Accept-Encoding/, @{$self->{o}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^Vary: Accept-Encoding/, @{$$self{"o"};}) 0 0 0
1501 0 push @{$self->{o}}, 'Vary: Accept-Encoding';
1502 }
1503 }
1504 } elsif($encoding eq 'zstd') {
1505 # Facebook
1506 0 ▶ if(eval { require Compress::Zstd; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Compress::Zstd; 1 } }) { } 0 0 0
1507 0 my $compressed_body = Compress::Zstd::compress(\Encode::_encode_utf8($self->{'body'}));
1508 0 ▶ if(length($compressed_body) < length($self->{'body'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $compressed_body < length $self->{"body"}) 0 0 0
1509 0 $self->{'body'} = $compressed_body;
1510 0 ▶ unless(grep(/^Content-Encoding: zstd/, @{$self->{o}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^Content-Encoding: zstd/, @{$$self{"o"};}) 0 0 0
1511 0 push @{$self->{o}}, 'Content-Encoding: zstd';
1512 }
1513 0 ▶ unless(grep(/^Vary: Accept-Encoding/, @{$self->{o}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^Vary: Accept-Encoding/, @{$$self{"o"};}) 0 0 0
1514 0 push @{$self->{o}}, 'Vary: Accept-Encoding';
1515 }
1516 }
1517 } else {
1518 0 $self->{status} = 406;
1519 0 ▶ if($self->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"info"}) 0 0 0
1520 0 $self->{'info'}->status(406);
1521 }
1522 }
1523 } elsif($encoding eq 'br') {
1524 1 ▶ if(eval { require IO::Compress::Brotli }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require IO::Compress::Brotli } }) { } 1 0 1
1525 1 IO::Compress::Brotli->import();
1526  
1527 1 ▶ unless($self->{_encode_loaded}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_encode_loaded"}) 0 1 1
1528 0 require Encode;
1529 0 $self->{_encode_loaded} = 1;
1530 }
1531 1 my $nbody = IO::Compress::Brotli::bro(Encode::encode_utf8($self->{body}));
1532 1 ▶ if(length($nbody) < length($self->{body})) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $nbody < length $self->{"body"}) 1 0 1
1533 1 $self->{body} = $nbody;
1534 1 ▶ unless(grep(/^Content-Encoding: br/, @{$self->{o}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^Content-Encoding: br/, @{$$self{"o"};}) 1 0 1
1535 1 push @{$self->{o}}, 'Content-Encoding: br';
1536 }
1537 1 ▶ unless(grep(/^Vary: Accept-Encoding/, @{$self->{o}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^Vary: Accept-Encoding/, @{$$self{"o"};}) 1 0 1
1538 1 push @{$self->{o}}, 'Vary: Accept-Encoding';
1539 }
1540 }
1541 } else {
1542 0 $self->{status} = 406;
1543 0 ▶ if($self->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"info"}) 0 0 0
1544 0 $self->{'info'}->status(406);
1545 }
1546 }
1547 }
1548 }
1549  
1550 sub _check_if_none_match {
1551 3 ▶ my $self = shift;
Subroutine _check_if_none_match: called CC=10 SCAR=37.3
1552  
1553 3 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 3 3
1554 0 $self->{logger}->debug("Compare $ENV{HTTP_IF_NONE_MATCH} with $self->{etag}");
1555 }
1556 3 ▶ if($ENV{'HTTP_IF_NONE_MATCH'} eq $self->{etag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"HTTP_IF_NONE_MATCH"} eq $self->{"etag"}) 3 0 3
1557 3 push @{$self->{o}}, 'Status: 304 Not Modified';
1558 3 $self->{send_body} = 0;
1559 3 $self->{status} = 304;
1560 3 ▶ if($self->{'info'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"info"}) 0 3 3
1561 0 $self->{'info'}->status(304);
1562 }
1563 3 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 3 3
1564 0 $self->{logger}->debug('Set status to 304');
1565 }
1566 3 return 1;
1567 }
1568 0 ▶ if($self->{cache} && $self->{logger} && $self->{logger}->is_debug()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cache"} and $self->{"logger"} and $self->{"logger"}->is_debug) 0 0 0
Condition0%0/6
$self->{"cache"} and $self->{"logger"} and $self->{"logger"}->is_debug
!ll&&!rl&&r
000
$self->{"cache"} and $self->{"logger"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"cache"} and $self->{"logger"} and $self->{"logger"}->is_debug
$self->{"cache"} $self->{"logger"} $self->{"logger"}->is_debug
Truth table0%0/4
A and B and C
A= $self->{"cache"}B= $self->{"logger"}C= $self->{"logger"}->is_debug
ABCresult
0XX0
10X0
1100
1111
1569 0 my $cached_copy = $self->{cache}->get($self->_generate_key());
1570  
1571 0 ▶ if($cached_copy && $self->{body}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cached_copy and $self->{'body'}) { } 0 0 0
Condition0%0/3
$cached_copy and $self->{"body"}
!ll&&!rl&&r
000
MC/DC0%0/2
$cached_copy and $self->{"body"}
$cached_copy $self->{"body"}
Truth table0%0/3
A and B
A= $cached_copyB= $self->{"body"}
ABresult
0X0
100
111
1572 0 require Text::Diff;
1573 0 Text::Diff->import();
1574  
1575 0 $cached_copy = Storable::thaw($cached_copy)->{body};
1576 0 my $diffs = diff(\$self->{body}, \$cached_copy);
1577 0 $self->{logger}->debug('diffs: ', $diffs);
1578 } else {
1579 0 $self->{logger}->debug('Nothing to compare');
1580 }
1581 }
1582 0 return 0;
1583 }
1584  
1585 # replace dynamic links with static links
1586 sub _save_to {
1587 28 ▶ my ($self, $unzipped_body, $dbh) = @_;
Subroutine _save_to: called CC=40 SCAR=73.3
1588  
1589 28 ▶ return 0 unless($dbh && $self->{info} && (my $request_uri = $ENV{'REQUEST_URI'}));
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh and $self->{"info"} and my $request_uri = $ENV{"REQUEST_URI"} 0 0 0
Condition33%2/6
$dbh and $self->{"info"} and my $request_uri = $ENV{"REQUEST_URI"}
!ll&&!rl&&r
2800
$dbh and $self->{"info"}
!ll&&!rl&&r
2800
MC/DC0%0/3
$dbh and $self->{"info"} and my $request_uri = $ENV{"REQUEST_URI"}
$dbh $self->{"info"} my $request_uri = $ENV{"REQUEST_URI"}
Truth table25%1/4
A and B and C
A= $dbhB= $self->{"info"}C= my $request_uri = $ENV{"REQUEST_URI"}
ABCresult
0XX0
10X0
1100
1111
1590 0 ▶ return 0 if(!defined($unzipped_body));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $unzipped_body 0 0 0
1591  
1592 0 my $query;
1593 0 my $copy = $unzipped_body;
1594 0 my $changes = 0;
1595 0 my $creation;
1596 my %seen_links;
1597 0 ▶ while($unzipped_body =~ /<a\shref="(.+?)"/gis) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unzipped_body =~ /<a\shref="(.+?)"/sig) 0 0 0
1598 0 my $link = $1;
1599 0 ▶ next if($seen_links{$link}); # Already updated in the copy
Branch: 1 branch
BranchTrueFalseTotal
if $seen_links{$link} 0 0 0
1600 0 $seen_links{$link} = 1;
1601 0 $link =~ tr/[\|;]/_/;
1602  
1603 0 my $search_uri = $link;
1604 0 ▶ if($search_uri =~ /^\?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($search_uri =~ /^\?/) { } 0 0 0
1605 # CGI script has links to itself
1606 # $search_uri = "${request_uri}${link}";
1607 0 my $r = $request_uri;
1608 0 $r =~ s/\?.*$//;
1609 0 $search_uri = "${r}$link";
1610 } else {
1611 0 ▶ next if($link =~ /^https?:\/\//); # FIXME: skips full URLs to ourself
Branch: 1 branch
BranchTrueFalseTotal
if $link =~ m[^https?://] 0 0 0
1612 # Though optimise_content fixes that
1613 0 ▶ next if($link =~ /.html?$/);
Branch: 1 branch
BranchTrueFalseTotal
if $link =~ /.html?$/ 0 0 0
1614 0 ▶ next if($link =~ /.jpg$/);
Branch: 1 branch
BranchTrueFalseTotal
if $link =~ /.jpg$/ 0 0 0
1615 0 ▶ next if($link =~ /.gif$/);
Branch: 1 branch
BranchTrueFalseTotal
if $link =~ /.gif$/ 0 0 0
1616 }
1617 0 ▶ if($self->{save_to}->{ttl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'save_to'}{'ttl'}) { } 0 0 0
1618 0 $query = "SELECT DISTINCT path, creation FROM fcgi_buffer WHERE uri = ? AND language = ? AND browser_type = ? AND creation >= strftime('\%s','now') - " . $self->{save_to}->{ttl};
1619 } else {
1620 0 $query = "SELECT DISTINCT path, creation FROM fcgi_buffer WHERE uri = ? AND language = ? AND browser_type = ?";
1621 }
1622 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
1623 0 $self->{logger}->debug("$query: $search_uri, ", $self->{lingua}->language(), ', ', $self->{info}->browser_type());
1624 }
1625 0 ▶ if(defined(my $sth = $dbh->prepare($query))) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $sth = $dbh->prepare($query))) { } 0 0 0
elsif ($self->{'logger'}) { } 0 0 0
1626 0 $sth->execute($search_uri, $self->{lingua}->language(), $self->{info}->browser_type());
1627 0 ▶ if(my $href = $sth->fetchrow_hashref()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $href = $sth->fetchrow_hashref) 0 0 0
1628 0 ▶ if(my $path = $href->{'path'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $href->{"path"}) 0 0 0
1629 0 ▶ if(-r $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $path) { } 0 0 0
1630 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
1631 0 $self->{logger}->debug("Changing links from $link to $path");
1632 }
1633 0 $link =~ s/\?/\\?/g;
1634 0 my $rootdir = $self->{info}->rootdir();
1635 0 $path = substr($path, length($rootdir));
1636 0 $changes += ($copy =~ s/<a\s+href="$link">/<a href="$path">/gis);
1637 # Find the first link that will expire and use that
1638 0 ▶ if((!defined($creation)) || ($href->{'creation'} < $creation)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $creation or $href->{"creation"} < $creation) 0 0 0
Condition0%0/3
not defined $creation or $href->{"creation"} < $creation
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $creation or $href->{"creation"} < $creation
not defined $creation $href->{"creation"} < $creation
Truth table0%0/3
not(A) or B
A= not defined $creationB= $href->{"creation"} < $creation
ABresult
1X1
011
000
1639 0 $creation = $href->{'creation'};
1640 }
1641 } else {
1642 0 $query = "DELETE FROM fcgi_buffer WHERE path = ?";
1643 0 $dbh->prepare($query)->execute($path);
1644 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
1645 0 $self->{logger}->warn("Remove entry for non-existant file $path");
1646 }
1647 }
1648 }
1649 }
1650 } elsif($self->{logger}) {
1651 0 $self->{logger}->warn("failed to prepare '$query'");
1652 }
1653 }
1654 0 my $expiration = 0;
1655 0 ▶ if(defined($creation) && (my $ttl = $self->{save_to}->{ttl})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $creation and my $ttl = $self->{"save_to"}{"ttl"}) 0 0 0
Condition0%0/3
defined $creation and my $ttl = $self->{"save_to"}{"ttl"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $creation and my $ttl = $self->{"save_to"}{"ttl"}
defined $creation my $ttl = $self->{"save_to"}{"ttl"}
Truth table0%0/3
A and B
A= defined $creationB= my $ttl = $self->{"save_to"}{"ttl"}
ABresult
0X0
100
111
1656 0 $expiration = $creation + $ttl;
1657 }
1658 0 ▶ if($changes && (($expiration == 0) || ($expiration >= time))) {
Branch: 2 branches
BranchTrueFalseTotal
if ($changes and $expiration == 0 || $expiration >= time) { } 0 0 0
elsif ($expiration and $expiration < time) { } 0 0 0
Condition0%0/6
$changes and $expiration == 0 || $expiration >= time
!ll&&!rl&&r
000
$expiration == 0 or $expiration >= time
l!l&&r!l&&!r
000
MC/DC0%0/3
$changes and $expiration == 0 || $expiration >= time
$changes $expiration == 0 $expiration >= time
Truth table0%0/4
A and B or C
A= $changesB= $expiration == 0C= $expiration >= time
ABCresult
0XX0
1000
11X1
1011
1659 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
1660 # $self->{logger}->debug("$changes links now point to static pages");
1661 0 ▶ if($changes == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changes == 1) { } 0 0 0
1662 0 ▶ if($self->{'save_to'}->{'ttl'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'save_to'}{'ttl'}) { } 0 0 0
1663 0 $self->{logger}->info('1 link now points to a static page for ', $expiration - time, 's');
1664 } else {
1665 0 $self->{logger}->info('1 link now points to a static page');
1666 }
1667 } else {
1668 0 $self->{logger}->info("$changes links now point to static pages");
1669 }
1670 }
1671 0 $unzipped_body = $copy;
1672 0 $self->{'body'} = $unzipped_body;
1673 0 ▶ if(my $ttl = $self->{save_to}->{ttl}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ttl = $self->{"save_to"}{"ttl"}) 0 0 0
1674 0 push @{$self->{o}}, 'Expires: ' . HTTP::Date::time2str($creation + $ttl);
1675 }
1676 ▶ } elsif($expiration && ($expiration < time)) {
Condition0%0/3
$expiration and $expiration < time
!ll&&!rl&&r
000
MC/DC0%0/2
$expiration and $expiration < time
$expiration $expiration < time
Truth table0%0/3
A and B
A= $expirationB= $expiration < time
ABresult
0X0
100
111
1677 # Delete the save_to files
1678 0 ▶ if($self->{save_to}->{ttl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'save_to'}{'ttl'}) { } 0 0 0
1679 0 $query = "SELECT path FROM fcgi_buffer WHERE creation < strftime('\%s','now') - " . $self->{save_to}->{ttl};
1680 } else {
1681 0 $query = 'SELECT path FROM fcgi_buffer'; # Hmm, I suspect this is overkill
1682 }
1683 0 my $sth = $dbh->prepare($query);
1684 0 $sth->execute();
1685 0 ▶ while(my $href = $sth->fetchrow_hashref()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $href = $sth->fetchrow_hashref) 0 0 0
1686 0 ▶ if(my $path = $href->{'path'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $href->{"path"}) 0 0 0
1687 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
1688 0 $self->{logger}->debug("unlink $path");
1689 }
1690 0 unlink $path;
1691 }
1692 }
1693 0 ▶ if($self->{save_to}->{ttl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'save_to'}{'ttl'}) { } 0 0 0
1694 0 $query = "DELETE FROM fcgi_buffer WHERE creation < strftime('\%s','now') - " . $self->{save_to}->{ttl};
1695 } else {
1696 0 $query = 'DELETE FROM fcgi_buffer'; # Hmm, I suspect this is overkill
1697 }
1698 0 ▶ if($self->{logger}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"logger"}) 0 0 0
1699 0 $self->{logger}->debug($query);
1700 }
1701 0 $dbh->prepare($query)->execute();
1702 # } else {
1703 # Old code
1704 # if($self->{save_to}->{ttl}) {
1705 # $query = "SELECT DISTINCT path, creation FROM fcgi_buffer WHERE key = '$key' AND creation >= strftime('\%s','now') - " . $self->{save_to}->{ttl};
1706 # } else {
1707 # $query = "SELECT DISTINCT path, creation FROM fcgi_buffer WHERE key = '$key'";
1708 # }
1709 # my $sth = $dbh->prepare($query);
1710 # $sth->execute();
1711 # my $href = $sth->fetchrow_hashref();
1712 # if(my $path = $href->{'path'}) {
1713 # # FIXME: don't do this if we've passed the TTL, and if we are clean
1714 # # up the database and remove the static page
1715 # $request_uri =~ s/\?/\\?/g;
1716 # if(($unzipped_body =~ s/<a href="$request_uri"/<a href="$path"/gi) > 0) {
1717 # $self->{'body'} = $unzipped_body;
1718 # if(my $ttl = $self->{save_to}->{ttl}) {
1719 # push @{$self->{o}}, 'Expires: ' . HTTP::Date::time2str($href->{creation} + $ttl);
1720 # }
1721 # }
1722 # }
1723 }
1724 0 return $changes;
1725 }
1726  
1727 =head1 AUTHOR
1728  
1729 Nigel Horne, C<< <njh at bandsman.co.uk> >>
1730  
1731 =head1 BUGS
1732  
1733 FCGI::Buffer should be safe even in scripts that produce lots of different
1734 output, e.g. e-commerce situations.
1735 On such pages, however, I strongly urge setting generate_304 to 0 and
1736 sending the HTTP header "Cache-Control: no-cache".
1737  
1738 When using L<Template>, ensure that you don't use it to output to STDOUT,
1739 instead,
1740 you will need to capture into a variable and print that.
1741 For example:
1742  
1743 my $output;
1744 $template->process($input, $vars, \$output) || ($output = $template->error());
1745 print $output;
1746  
1747 Can produce buggy JavaScript if you use the <!-- HIDING technique.
1748 This is a bug in L<JavaScript::Packer>, not FCGI::Buffer.
1749  
1750 Mod_deflate can confuse this when compressing output.
1751 Ensure that deflation is off for .pl files:
1752  
1753 SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|pl)$ no-gzip dont-vary
1754  
1755 If you request compressed output then uncompressed output (or vice
1756 versa) on input that produces the same output, the status will be 304.
1757 The letter of the spec says that's wrong, so I'm noting it here, but
1758 in practice, you should not see this happen or have any difficulties
1759 because of it.
1760  
1761 FCGI::Buffer has not been tested against FastCGI.
1762  
1763 I advise adding FCGI::Buffer as the last use statement so that it is
1764 cleared up first. In particular, it should be loaded after
1765 L<Log::Log4perl>, if you're using that, so that any messages it
1766 produces are printed after the HTTP headers have been sent by
1767 FCGI::Buffer;
1768  
1769 Save_to doesn't understand links in JavaScript, which means that if you use self-calling
1770 CGIs loaded as a static page,
1771 they may point to the wrong place.
1772 The workaround is to avoid self-calling CGIs in JavaScript
1773  
1774 Please report any bugs or feature requests to C<bug-fcgi-buffer at rt.cpan.org>
1775 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FCGI-Buffer>.
1776 I will be notified, and then you'll automatically be notified of the progress on
1777 your bug as I make changes.
1778  
1779 The lint operation only works on HTML4, because of a restriction in L<HTML::Lint>.
1780  
1781 =head1 SEE ALSO
1782  
1783 L<CGI::Buffer>,
1784 L<HTML::Packer>,
1785 L<HTML::Lint>
1786  
1787 =head1 SUPPORT
1788  
1789 You can find documentation for this module with the perldoc command.
1790  
1791 perldoc FCGI::Buffer
1792  
1793 You can also look for information at:
1794  
1795 =over 4
1796  
1797 =item * RT: CPAN's request tracker
1798  
1799 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=FCGI-Buffer>
1800  
1801 =item * Search CPAN
1802  
1803 L<http://search.cpan.org/dist/FCGI-Buffer/>
1804  
1805 =back
1806  
1807 =head1 ACKNOWLEDGEMENTS
1808  
1809 The inspiration and code for some of this is cgi_buffer by Mark
1810 Nottingham: L<https://www.mnot.net/blog/2003/04/24/etags>.
1811  
1812 =head1 LICENSE AND COPYRIGHT
1813  
1814 The licence for cgi_buffer is:
1815  
1816 "(c) 2000 Copyright Mark Nottingham <mnot@pobox.com>
1817  
1818 This software may be freely distributed, modified and used,
1819 provided that this copyright notice remain intact.
1820  
1821 This software is provided 'as is' without warranty of any kind."
1822  
1823 The rest of the program is Copyright 2015-2025 Nigel Horne,
1824 and is released under the following licence: GPL2
1825  
1826 =cut
1827  
1828 11 1; # End of FCGI::Buffer
↑ Summary