FCGI-Buffer

 view release on metacpan or  search on metacpan

t/cache.t  view on Meta::CPAN


		ok($b->can_cache() == 1);

		print "Content-type: text/html; charset=ISO-8859-1\n\n";

		print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN>\n",
			"<HTML><HEAD><TITLE>Hello, world</TITLE></HEAD>",
			"<BODY><P>The quick brown fox jumped over the lazy dog.</P>",
			'<A HREF="?arg1=a&arg2=b">link</a>',
			'<A HREF="?arg1=a&arg2=b">link</a>',
			"</BODY></HTML>\n";
	}

	($stdout, $stderr) = capture { test5b() };
	ok($stderr eq '');

	($headers, $body) = split /\r?\n\r?\n/, $stdout, 2;

	ok($headers =~ /Content-type: text\/html; charset=ISO-8859-1/mi);
	ok($headers =~ /^ETag:\s+.+/m);
	ok($headers =~ /^Expires: /m);
	ok($headers !~ /^Content-Encoding: gzip/m);

	if($^O eq 'MSWin32') {
		ok($body =~ /\\web\\English\\test4.cgi\\.+\.html"/m);
	} else {
		ok($body =~ /"\/web\/English\/test4.cgi\/.+\.html"/m);
	}
	ok($body !~ /"\?arg1=a/m);

	ok($headers =~ /^Content-Length:\s+(\d+)/m);
	$length = $1;
	ok(defined($length));
	ok(length($body) eq $length);

	# Check zipping returns save_to correctly
	$ENV{'HTTP_ACCEPT_ENCODING'} = 'gzip';
	($stdout, $stderr) = capture { test5b() };
	ok($stderr eq '');

	($headers, $body) = split /\r?\n\r?\n/, $stdout, 2;

	ok($headers =~ /Content-type: text\/html; charset=ISO-8859-1/mi);
	ok($headers =~ /^ETag:\s+.+/m);
	ok($headers =~ /^Expires: /m);
	like($headers, qr/^Content-Encoding:\sgzip\r?$/m, 'Contains content-encoding gzip header');

	ok($headers =~ /^Content-Length:\s+(\d+)/m);
	$length = $1;
	ok(defined($length));
	ok(length($body) eq $length);

	my $h = HTTP::Headers->new();
	foreach my $header(split(/\r?\n/, $headers)) {
		my ($key, $value) = split(/:\s?/, $header, 2);
		$h->header($key => $value);
	}
	my $r = HTTP::Response->new(200, 'OK', $h, $body);
	ok($h->content_encoding() eq 'gzip');

	$body = $r->decoded_content();
	if($^O eq 'MSWin32') {
		ok($body =~ /\\web\\English\\test4.cgi\\.+\.html"/m);
	} else {
		ok($body =~ /"\/web\/English\/test4.cgi\/.+\.html"/m);
	}
	ok($body !~ /"\?arg1=a/m);

	$ENV{'REQUEST_METHOD'} = 'HEAD';
	$ENV{'HTTP_ACCEPT_ENCODING'} = 'gzip';
	($stdout, $stderr) = capture { test5b() };
	ok($stderr eq '');

	($headers, $body) = split /\r?\n\r?\n/, $stdout, 2;

	ok($headers =~ /Content-type: text\/html; charset=ISO-8859-1/mi);
	ok($headers =~ /^ETag:\s+.+/m);
	ok($headers =~ /^Expires: /m);
	like($headers, qr/^Content-Encoding:\sgzip\r?$/m, 'Contains content-encoding gzip header');

	ok($body eq '');

	ok(-r "$tempdir/fcgi.buffer.sql");
	ok(-d "$tempdir/web/English/test4.cgi");
	ok(-d "$tempdir/web/English/test5.cgi");

	# ...............................
	$ENV{'SCRIPT_NAME'} = '/cgi-bin/test6.cgi';
	$ENV{'REQUEST_URI'} = '/cgi-bin/test6.cgi?foo=bar';
	$ENV{'REQUEST_METHOD'} = 'GET';
	delete $ENV{'HTTP_ACCEPT_ENCODING'};

	sub test6 {
		my $b = new_ok('FCGI::Buffer');
		my $info = new_ok('CGI::Info');

		$save_to->{'ttl'} = 0;
		$b->init({
			info => $info,
			cache => $cache,
			lingua => CGI::Lingua->new(
				supported => ['en'],
				dont_use_ip => 1,
				info => $info,
			),
			save_to => $save_to,
			logger => MyLogger->new(),
			optimise_content => 1,
		});

		ok($b->can_cache() == 1);

		print "Content-type: text/html; charset=ISO-8859-1\n\n";

		print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN>\n",
			"<HTML><HEAD><TITLE>test6</TITLE></HEAD>",
			"<BODY>",
			'<A HREF="/cgi-bin/test6.cgi?arg2=b">link</a>',
			'<A HREF="http://github.com/nigelhorne/FCGI-Buffer">link2</a>',
			'<A HREF="/cgi-bin/test4.cgi?arg3=c">link3</a>',
			'<A HREF="/cgi-bin/test4.cgi?arg1=a&arg2=b">link4</a>',



( run in 1.150 second using v1.01-cache-2.11-cpan-39bf76dae61 )