Some of the repetitive violations were suppressed.
17.24KiB; Perl | 2021-02-26 14:28:32+01 | Statements 424 | SLOC 495
1
#!perl -w
2
3
# Test if CGI::Buffer adds Content-Length and Etag headers, also simple
4
# check that optimise_content does something.
5
6
# TODO: check optimise_content and gzips do the *right* thing
7
# TODO: check ETags are correct
8
# TODO: Write a test to check that 304 is sent when a cached object
9
10
use strict;
11
use warnings;
12
13
use Test::Most tests => 101;
14
use Compress::Zlib;
15
use Test::TempDir::Tiny;
16
use IO::Uncompress::Brotli;
17
use DateTime;
18
use Test::HTML::Lint;
19
# use Test::NoWarnings;	# HTML::Clean has them
20
eval 'use autodie qw(:all)';	# Test for open/close failures
21
22
BEGIN {
23
	use_ok('CGI::Buffer');
24
}
25
26
OUTPUT: {
27
	delete $ENV{'HTTP_ACCEPT_ENCODING'};
28
	delete $ENV{'HTTP_TE'};
29
	delete $ENV{'SERVER_PROTOCOL'};
30
	delete $ENV{'HTTP_RANGE'};
31
32
	$ENV{'REQUEST_METHOD'} = 'GET';
33
34
	my $filename = tempdir() . 'test1';
35
	open(my $tmp, '>', $filename);
36
	print $tmp "use strict;\n",
37
		"use CGI::Buffer;\n",
38
		"print \"Content-type: text/html; charset=ISO-8859-1\";\n",
39
		"print \"\\n\\n\";\n",
40
		"print \"<HTML><BODY>   Hello, world</BODY></HTML>\\n\";\n";
41
42
	open(my $fin, '-|', "$^X -Iblib/lib " . $filename);
43
44
	my $keep = $_;
45
	undef $/;
46
	my $output = <$fin>;
47
	$/ = $keep;
48
49
	close $tmp;
50
51
	ok($output !~ /^ETag: "/m);
52
	ok($output !~ /^Content-Encoding: gzip/m);
53
54
	my ($headers, $body) = split /\r?\n\r?\n/, $output, 2;
55
56
	ok($headers =~ /^Content-Length:\s+(\d+)/m);
57 1
	my $length = $1;
58
	ok(defined($length));
59
60
	ok($body eq "<HTML><BODY>   Hello, world</BODY></HTML>\n");
61
	ok(length($body) eq $length);
62
63
	$filename = tempdir() . 'test2';
64
	open($tmp, '>', $filename);
65
	print $tmp "use CGI::Buffer;\n";
66
	print $tmp "CGI::Buffer::set_options(optimise_content => 1);\n";
67
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n";
68
	print $tmp "print \"\\n\\n\";\n";
69
	print $tmp "print \"<HTML>\\n<BODY>\\n\\t    Hello, world\\n  </BODY>\\n</HTML>\\n\";\n";
70
71
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
72
73
	$keep = $_;
74
	undef $/;
75
	$output = <$fin>;
76
	$/ = $keep;
77
78
	close $tmp;
79
80
	ok($output =~ /^Content-Length:\s+(\d+)/m);
81 1
	$length = $1;
82
	ok(defined($length));
83
	# Extra spaces should have been removed
84
	ok($output =~ /<HTML><BODY>Hello, world<\/BODY><\/HTML>/mi);
85
	ok($output !~ /^Content-Encoding: gzip/m);
86
	ok($output !~ /^ETag: "/m);
87
88
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
89
	ok(defined($headers));
90
	ok(defined($body));
91
	ok(length($body) eq $length);
92
93
	$ENV{'HTTP_ACCEPT_ENCODING'} = 'gzip, deflate, sdch, br';
94
95
	$filename = tempdir() . 'test3';
96
	open($tmp, '>', $filename);
97
	print $tmp "use CGI::Buffer;\n";
98
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n";
99
	print $tmp "print \"\\n\\n\";\n";
100
	print $tmp "print \"<HTML><HEAD>Test</HEAD><BODY><P>Hello, world></BODY></HTML>\\n\";\n";
101
102
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
103
104
	$keep = $_;
105
	undef $/;
106
	$output = <$fin>;
107
	$/ = $keep;
108
109
	close $tmp;
110
111
	ok($output =~ /^Content-Length:\s+(\d+)/m);
112 1
	$length = $1;
113
	ok(defined($length));
114
	# It's not gzipped, because it's so small the gzip version would be
115
	# bigger
116
	ok($output =~ /<HTML><HEAD>Test<\/HEAD><BODY><P>Hello, world><\/BODY><\/HTML>/m);
117
	ok($output !~ /^Content-Encoding: gzip/m);
118
	ok($output !~ /^ETag: "/m);
119
120
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
121
	ok(length($body) eq $length);
122
123
	$ENV{'SERVER_PROTOCOL'} = 'HTTP/1.1';
124
	$ENV{'HTTP_ACCEPT_ENCODING'} = undef;
125
	# delete($ENV{'HTTP_ACCEPT_ENCODING'});
126
	$ENV{'HTTP_TE'} = 'br,gzip';
127
128
	$filename = tempdir() . 'test4';
129
	open($tmp, '>', $filename);
130
	if($ENV{'PERL5LIB'}) {
131
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
132
			print $tmp "use lib '$_';\n";
133
		}
134
	}
135
	print $tmp "use CGI::Buffer {optimise_content => 0};\n",
136
		"print \"Content-type: text/html; charset=ISO-8859-1\\n\";\n",
137
		"print \"X-foo: \$ENV{HTTP_TE}\\n\";\n",
138
		"print \"X-foo: \$ENV{HTTP_ACCEPT_ENCODING}\\n\";\n",
139
		"print \"\\n\";\n";
140
	# Put in a large body so that it gzips - small bodies won't
141
	print $tmp "print \"<!DOCTYPE HTML PUBLIC \\\"-//W3C//DTD HTML 4.01 Transitional//EN\\\">\\n\";\n",
142
		"print \"<HTML><HEAD><TITLE>Hello, world</TITLE></HEAD><BODY><P>The quick brown fox jumped over the lazy dog.</P></BODY></HTML>\\n\";\n";
143
144
	open($fin, '-|', "$^X -Iblib/lib $filename");
145
146
	$keep = $_;
147
	undef $/;
148
	$output = <$fin>;
149
	$/ = $keep;
150
151
	close $tmp;
152
153
	ok($output =~ /^Content-Length:\s+(\d+)/m);
154 1
	$length = $1;
155
	ok(defined($length));
156
157
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
158
	ok($headers =~ /^Content-Encoding: br/m);
159
	ok($headers =~ /ETag: "[A-Za-z0-F0-f]{32}"/m);
160
161
	ok(defined($body));
162
	ok(length($body) eq $length);
163
	$body = unbro($body, 1024);
164
	ok(defined($body));
165
	ok($body =~ /<HTML><HEAD><TITLE>Hello, world<\/TITLE><\/HEAD><BODY><P>The quick brown fox jumped over the lazy dog.<\/P><\/BODY><\/HTML>\n$/);
166
	html_ok($body, 'HTML:Lint shows no errors');
167
168
	#..........................................
169
	delete $ENV{'SERVER_PROTOCOL'};
170
	delete $ENV{'HTTP_TE'};
171
172
	$ENV{'SERVER_NAME'} = 'www.example.com';
173
174
	$filename = tempdir() . 'test5';
175
	open($tmp, '>', $filename);
176
	if($ENV{'PERL5LIB'}) {
177
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
178
			print $tmp "use lib '$_';\n";
179
		}
180
	}
181
	print $tmp "use CGI::Buffer;\n",
182
		"CGI::Buffer::set_options({ optimise_content => 1 });\n",
183
		"print \"Content-type: text/html; charset=ISO-8859-1\";\n",
184
		"print \"\\n\\n\";\n",
185
		"print \"<HTML><BODY><A HREF=\\\"http://www.example.com\\\">Click</A>\n<script>\nalert(foo);\n</script></BODY></HTML>\\n\";\n";
186
187
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
188
189
	$keep = $_;
190
	undef $/;
191
	$output = <$fin>;
192
	$/ = $keep;
193
194
	close $tmp;
195
196
	ok($output =~ /href="\/"/m);
197
	ok($output !~ /<script>\s/m);
198
199
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
200
	ok($headers =~ /^Content-Length:\s+(\d+)/m);
201 1
	$length = $1;
202
	ok(defined($length));
203
204
	ok(length($body) eq $length);
205
	ok($body !~ /www.example.com/m);
206
207
	#..........................................
208
	$filename = tempdir() . 'test6';
209
	open($tmp, '>', $filename);
210
	if($ENV{'PERL5LIB'}) {
211
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
212
			print $tmp "use lib '$_';\n";
213
		}
214
	}
215
	print $tmp "use CGI::Buffer;\n";
216
	print $tmp "CGI::Buffer::set_options(optimise_content => 1);\n";
217
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n";
218
	print $tmp "print \"\\n\\n\";\n";
219
	print $tmp "print \"<HTML><BODY><A HREF= \\\"http://www.example.com/foo.htm\\\">Click</A></BODY></HTML>\\n\";\n";
220
221
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
222
223
	$keep = $_;
224
	undef $/;
225
	$output = <$fin>;
226
	$/ = $keep;
227
228
	close $tmp;
229
230
	ok($output =~ /href="\/foo.htm"/m);
231
	ok($output =~ /^Content-Length:\s+(\d+)/m);
232 1
	$length = $1;
233
	ok(defined($length));
234
235
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
236
	ok(length($body) eq $length);
237
	ok($body !~ /www.example.com/m);
238
239
	#..........................................
240
	$filename = tempdir() . 'test7';
241
	open($tmp, '>', $filename);
242
	if($ENV{'PERL5LIB'}) {
243
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
244
			print $tmp "use lib '$_';\n";
245
		}
246
	}
247
	print $tmp "use CGI::Buffer;\n";
248
	print $tmp "CGI::Buffer::set_options(optimise_content => 1, lint_content=> 1);\n";
249
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n",
250
		"print \"\\n\\n\";\n",
251
		"print \"<HTML><HEAD><TITLE>test 7</TITLE></HEAD><BODY><A HREF= \n\\\"http://www.example.com/foo.htm\\\">Click</A></BODY></HTML>\\n\";\n";
252
253
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
254
255
	$keep = $_;
256
	undef $/;
257
	$output = <$fin>;
258
	$/ = $keep;
259
260
	close $tmp;
261
262
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
263
264
	ok($headers =~ /^Content-Length:\s+(\d+)/m);
265 1
	$length = $1;
266
	ok(defined($length));
267
	ok(length($body) eq $length);
268
	ok($body =~ /href="\/foo.htm"/mi);
269
	# Server is www.example.com (set in a previous test), so the href
270
	# should be optimised, therefore www.example.com shouldn't appear
271
	# anywhere at all
272
	ok($body !~ /www\.example\.com/m);
273
274
	#..........................................
275
	# Check for removal of consecutive white space between links
276
	delete $ENV{'HTTP_TE'};
277
	$filename = tempdir() . 'test8';
278
	open($tmp, '>', $filename);
279
	if($ENV{'PERL5LIB'}) {
280
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
281
			print $tmp "use lib '$_';\n";
282
		}
283
	}
284
	print $tmp "use CGI::Buffer;\n",
285
		"CGI::Buffer::set_options(optimise_content => 1, lint_content=> 1);\n",
286
		"print \"Content-type: text/html; charset=ISO-8859-1\";\n",
287
		"print \"\\n\\n\";\n",
288
		"print \"<HTML><HEAD><TITLE>test 8</TITLE></HEAD><BODY><A HREF= \n\\\"http://www.example.com/foo.htm\\\">Click </A> \\n\\t<a href=\\\"http://www.example.com/bar.htm\\\">Or here</a> </BODY></HTML>\\n\";\n";
289
290
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
291
292
	$keep = $_;
293
	undef $/;
294
	$output = <$fin>;
295
	$/ = $keep;
296
297
	close $tmp;
298
299
	ok($output =~ /<a href="\/foo\.htm">Click<\/A> <a href="\/bar\.htm">Or here<\/a>/mi);
300
301
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
302
303
	ok($headers =~ /^Content-Length:\s+(\d+)/m);
304 1
	$length = $1;
305
	ok(defined($length));
306
	ok(length($body) eq $length);
307
	ok($body =~ /href="\/foo.htm"/mi);
308
	# Server is www.example.com (set in a previous test), so the href
309
	# should be optimised, therefore www.example.com shouldn't appear
310
	# anywhere at all
311
	ok($body !~ /www\.example\.com/m);
312
313
	#..........................................
314
315
	$filename = tempdir() . 'test9';
316
	open($tmp, '>', $filename);
317
	if($ENV{'PERL5LIB'}) {
318
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
319
			print $tmp "use lib '$_';\n";
320
		}
321
	}
322
	print $tmp "use CGI::Buffer;\n";
323
	print $tmp "CGI::Buffer::set_options(optimise_content => 1);\n";
324
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n";
325
	print $tmp "print \"\\n\\n\";\n";
326
	print $tmp "print \"<HTML><BODY><A HREF=\\\"http://www.example.com/foo.htm\\\">Click</a> <hr> A Line \n<HR>\r\n Foo</BODY></HTML>\\n\";\n";
327
328
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
329
330
	$keep = $_;
331
	undef $/;
332
	$output = <$fin>;
333
	$/ = $keep;
334
335
	close $tmp;
336
337
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
338
	ok($headers =~ /^Content-Length:\s+(\d+)/m);
339 1
	$length = $1;
340
	ok(defined($length));
341
	ok(length($body) eq $length);
342
	ok($headers !~ /^Status: 500/m);
343
	ok($body =~ /<hr>A Line<hr>Foo/);
344
345
	#..........................................
346
	# Space left intact after </em>
347
	$filename = tempdir() . 'test10';
348
	open($tmp, '>', $filename);
349
	if($ENV{'PERL5LIB'}) {
350
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
351
			print $tmp "use lib '$_';\n";
352
		}
353
	}
354
	print $tmp "use CGI::Buffer { optimise_content => 1, lint_content => 0 };\n";
355
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n";
356
	print $tmp "print \"\\n\\n\";\n";
357
	print $tmp "print \"<HTML><BODY>\n<p><em>The Brass Band Portal</em> is visited some 500 times</BODY></HTML>\\n\";\n";
358
359
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
360
361
	$keep = $_;
362
	undef $/;
363
	$output = <$fin>;
364
	$/ = $keep;
365
366
	close $tmp;
367
368
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
369
	ok($headers =~ /^Content-Length:\s+(\d+)/m);
370 1
	$length = $1;
371
	ok(defined($length));
372
	ok(length($body) eq $length);
373
	ok($headers !~ /^Status: 500/m);
374
	ok($body eq "<HTML><BODY><p><em>The Brass Band Portal</em> is visited some 500 times</BODY></HTML>");
375
376
	#..........................................
377
	diag('Ignore warning about <a> is never closed');
378
	delete $ENV{'SERVER_NAME'};
379
	$filename = tempdir() . 'test11';
380
	open($tmp, '>', $filename);
381
	if($ENV{'PERL5LIB'}) {
382
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
383
			print $tmp "use lib '$_';\n";
384
		}
385
	}
386
	print $tmp "use CGI::Buffer;\n";
387
	print $tmp "CGI::Buffer::set_options(optimise_content => 1, lint_content=> 1);\n";
388
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n";
389
	print $tmp "print \"\\n\\n\";\n";
390
	print $tmp "print \"<HTML><BODY><A HREF=\\\"http://www.example.com/foo.htm\\\">Click</BODY></HTML>\\n\";\n";
391
392
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
393
394
	$keep = $_;
395
	undef $/;
396
	$output = <$fin>;
397
	$/ = $keep;
398
399
	close $tmp;
400
401
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
402
	ok($headers =~ /^Content-Length:\s+(\d+)/m);
403
	$length = $1;
404
	ok(defined($length));
405
	ok(length($body) eq $length);
406
	ok($headers =~ /^Status: 500/m);
407
	ok($body =~ /<a>.+is never closed/);
408
409
	#..........................................
410
	$ENV{'SERVER_PROTOCOL'} = 'HTTP/1.1';
411
	delete $ENV{'HTTP_ACCEPT_ENCODING'};
412
413
	$filename = tempdir() . 'test12';
414
	open($tmp, '>', $filename);
415
	if($ENV{'PERL5LIB'}) {
416
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
417
			print $tmp "use lib '$_';\n";
418
		}
419
	}
420
	print $tmp "use CGI::Buffer;\n";
421
	print $tmp "CGI::Buffer::set_options({optimise_content => 1});\n";
422
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n";
423
	print $tmp "print \"\\n\\n\";\n";
424
	print $tmp "print \"<HTML><BODY><TABLE><TR><TD>foo</TD>  <TD>bar</TD></TR></TABLE></BODY></HTML>\\n\";\n";
425
426
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
427
428
	$keep = $_;
429
	undef $/;
430
	$output = <$fin>;
431
	$/ = $keep;
432
433
	ok($output =~ /<TD>foo<\/TD><TD>bar<\/TD>/mi);
434
	ok($output =~ /^Content-Length:\s+(\d+)/m);
435
	$length = $1;
436
	ok(defined($length));
437
438
	ok($output =~ /ETag: "([A-Za-z0-F0-f]{32})"/m);
439
	my $etag = $1;
440
	ok(defined($etag));
441
442
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
443
	ok(length($body) eq $length);
444
	ok(length($body) > 0);
445
446
	#..........................................
447
	$ENV{'HTTP_IF_NONE_MATCH'} = "\"$etag\"";
448
449
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
450
451
	$keep = $_;
452
	undef $/;
453
	$output = <$fin>;
454
	$/ = $keep;
455
456
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
457
	ok($headers =~ /^Status: 304 Not Modified/mi);
458
	ok(length($body) == 0);
459
460
	$ENV{'REQUEST_METHOD'} = 'HEAD';
461
462
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
463
464
	$keep = $_;
465
	undef $/;
466
	$output = <$fin>;
467
	$/ = $keep;
468
469
	close $tmp;
470
471
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
472
	ok($headers =~ /^Status: 304 Not Modified/mi);
473
	ok(length($body) == 0);
474
475
	#..........................................
476
	$ENV{'SERVER_PROTOCOL'} = 'HTTP/1.1';
477
	delete $ENV{'HTTP_ACCEPT_ENCODING'};
478
	$ENV{'REQUEST_METHOD'} = 'GET';
479
480
	$filename = tempdir() . 'test13';
481
	open($tmp, '>', $filename);
482
	print $tmp "use CGI::Buffer;\n";
483
	if($ENV{'PERL5LIB'}) {
484
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
485
			print $tmp "use lib '$_';\n";
486
		}
487
	}
488
	print $tmp "CGI::Buffer::set_options(optimise_content => 1, generate_304 => 0);\n";
489
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n";
490
	print $tmp "print \"\\n\\n\";\n";
491
	print $tmp "print \"<HTML><BODY><TABLE><TR><TD>foo</TD>\\t  <TD>bar</TD></TR></TABLE></BODY></HTML>\\n\";\n";
492
493
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
494
495
	$keep = $_;
496
	undef $/;
497
	$output = <$fin>;
498
	$/ = $keep;
499
500
	close $tmp;
501
502
	ok(defined($output));
503
	ok($output =~ /<TD>foo<\/TD><TD>bar<\/TD>/mi);
504
	ok($output !~ /^Status: 304 Not Modified/mi);
505
	ok($output =~ /^Content-Length:\s+(\d+)/m);
506
	$length = $1;
507
	ok(defined($length));
508
509
	ok($output =~ /ETag: "([A-Za-z0-F0-f]{32})"/m);
510
	$etag = $1;
511
	ok(defined($etag));
512
513
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
514
	ok(defined($length));
515
	ok(length($body) eq $length);
516
	ok(length($body) > 0);
517
518
	#..........................................
519
	$ENV{'HTTP_IF_NONE_MATCH'} = $etag;
520
521
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
522
523
	$keep = $_;
524
	undef $/;
525
	$output = <$fin>;
526
	$/ = $keep;
527
528
	ok($output !~ /^Status: 304 Not Modified/mi);
529
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
530
	ok(length($body) > 0);
531
532
	#..........................................
533
	delete $ENV{'HTTP_IF_NONE_MATCH'};
534
	$ENV{'HTTP_IF_MODIFIED_SINCE'} = DateTime->now();
535
536
	$filename = tempdir() . 'test14';
537
	open($tmp, '>', $filename);
538
	if($ENV{'PERL5LIB'}) {
539
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
540
			print $tmp "use lib '$_';\n";
541
		}
542
	}
543
	print $tmp "use CGI::Buffer { optimise_content => 1, generate_etag => 0 };\n",
544
		"print \"Content-type: text/html; charset=ISO-8859-1\";\n",
545
		"print \"\\n\\n\";\n",
546
		"print \"<HTML><BODY><TABLE><TR><TD>foo</TD>  <TD>bar</TD></TR></TABLE></BODY></HTML>\\n\";\n";
547
548
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
549
550
	$keep = $_;
551
	undef $/;
552
	$output = <$fin>;
553
	$/ = $keep;
554
555
	close $tmp;
556
557
	ok($output !~ /ETag: "([A-Za-z0-F0-f]{32})"/m);
558
	ok($output =~ /^Status: 304 Not Modified/mi);
559
560
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
561
562
	ok($headers !~ /^Content-Length:/m);
563
564
	ok(length($body) == 0);
565
566
	#......................................
567
	$ENV{'HTTP_IF_MODIFIED_SINCE'} = 'This is an invalid date';
568
569
	$filename = tempdir() . 'test15';
570
	open($tmp, '>', $filename);
571
	if($ENV{'PERL5LIB'}) {
572
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
573
			print $tmp "use lib '$_';\n";
574
		}
575
	}
576
	print $tmp "use CGI::Buffer { optimise_content => 1, generate_etag => 0 };\n";
577
	print $tmp "print \"Content-type: text/html; charset=ISO-8859-1\";\n";
578
	print $tmp "print \"\\n\\n\";\n";
579
	print $tmp "print \"<HTML><BODY><TABLE><TR><TD>foo</TD>   <TD>bar</TD></TR></TABLE></BODY></HTML>\\n\";\n";
580
581
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
582
583
	$keep = $_;
584
	undef $/;
585
	$output = <$fin>;
586
	$/ = $keep;
587
588
	close $tmp;
589
590
	ok($output !~ /ETag: "([A-Za-z0-F0-f]{32})"/m);
591
	ok($output !~ /^Status: 304 Not Modified/mi);
592
593
	($headers, $body) = split /\r?\n\r?\n/, $output, 2;
594
595
	ok($headers =~ /^Content-Length:\s+(\d+)/m);
596
	$length = $1;
597
598
	ok(length($body) != 0);
599
	ok(defined($length));
600
	ok(length($body) == $length);
601
602
	#......................................
603
	# Check no output does nothing strange
604
605
	delete $ENV{'HTTP_IF_MODIFIED_SINCE'};
606
607
	$filename = tempdir() . 'test16';
608
	open($tmp, '>', $filename);
609
	if($ENV{'PERL5LIB'}) {
610
		foreach (reverse split(/:/, $ENV{'PERL5LIB'})) {
611
			print $tmp "use lib '$_';\n";
612
		}
613
	}
614
	print $tmp "use strict;\n",
615
		"use CGI::Buffer;\n";
616
617
	open($fin, '-|', "$^X -Iblib/lib " . $filename);
618
619
	$keep = $_;
620
	undef $/;
621
	$output = <$fin>;
622
	$/ = $keep;
623
624
	close $tmp;
625
	close $fin;
626
627
	ok($output eq '');
628
}