#!/usr/bin/perl
# Print out compressed pages

$file = "faq.html.gz";

use HTTP::Date;
	
@stat = stat($0) or die ("Could not get statistics for script file");
$mylastmodtime = $stat[9];
$mylastmod = time2str($mylastmodtime);

if ($ENV{'HTTP_ACCEPT_ENCODING'} =~ m/gzip/)
{
	@stat = stat($file) or die ("Could not get statistics for compressed file");
	$lastmodtime = $stat[9];

	if ($mylastmodtime > $lastmodtime)
	{
		$lastmodtime = $mylastmodtime;
	}

	$lastmod = time2str($lastmodtime);

	if ($ims = $ENV{'HTTP_IF_MODIFIED_SINCE'})
	{
		$ims =~ s/;.*//;
		$imstime = str2time($ims);

		if ($lastmodtime <= $imstime)
		{
  			print "Status: 304 Not Modified\n\n";
  			exit;
  		}
	}

	print "Content-Type: text/html\n";
	print "Content-Encoding: gzip\n";
	print "Last-Modified: $lastmod\n\n";

	open (COMP, $file) or die ("Could not open compressed file");

	binmode (COMP);

	print <COMP>;

	close (COMP);
}
else
{
	print "Content-Type: text/html\n";
	print "Last-Modified: $mylastmod\n\n";

	print "<html><head><title>GeForce FAQ</title><meta http-equiv=\"Refresh\" content=\"5; URL=faq.html\"></head><h1>Your browser does not support gzip compression. Try enabling the HTTP 1.1 protocol or using a newer browser.</h1><h2>You will be automatically redirected to the <a href=\"faq.html\">uncompressed version</a> in 5 seconds if your browser supports redirects.</h2></html>";
}