r3752 jmb - /trunk/netsurfweb/cgissi.fcgi

netsurf at semichrome.net netsurf at semichrome.net
Mon Jan 21 23:58:56 GMT 2008


Author: jmb
Date: Mon Jan 21 23:58:55 2008
New Revision: 3752

URL: http://source.netsurf-browser.org?rev=3752&view=rev
Log:
Reinstate creation of ETag and Last-Modified headers.
Our ETag generation involves base64 encoding the md5sum of the data buffer.

Modified:
    trunk/netsurfweb/cgissi.fcgi

Modified: trunk/netsurfweb/cgissi.fcgi
URL: http://source.netsurf-browser.org/trunk/netsurfweb/cgissi.fcgi?rev=3752&r1=3751&r2=3752&view=diff
==============================================================================
--- trunk/netsurfweb/cgissi.fcgi (original)
+++ trunk/netsurfweb/cgissi.fcgi Mon Jan 21 23:58:55 2008
@@ -9,9 +9,10 @@
 use warnings;
 use strict;
 
-use POSIX qw(strftime);
+use Digest::MD5;
 use File::Spec;
 use FCGI;
+use POSIX qw(strftime);
 
 # Content cache to avoid regenerating pages unless it's absolutely necessary
 #
@@ -20,6 +21,7 @@
 #
 # { "/foo/bar/baz" => 
 # 	{ last_modified => 0123456789,
+# 	  data_digest => "base64(MD5($data))"
 # 	  data_last_modified => 0123456789,
 #	  data => "generated page content",
 #	  dependencies => 
@@ -59,15 +61,17 @@
 	# (as it may have been created by validate_cache_entry)
 	$cachedata = $cache{$docroot . $path};
 
-	# TODO It would be really nice to be able to send 304 responses where
-	# appropriate. We have the appropriate information in 
-	# $$cachedata{data_last_modified}. I guess, if necessary, we could also
-	# generate an E-tag. Currently, I can see no sensible way of doing this.
+	# TODO It would be nice to send 304 responses where appropriate
+	# and also to pay attention to conditional requests namely
+	# If-(None-)Match and If-(Un)Modified-Since
+
+	# Cache-related headers
+	print "ETag: " . $$cachedata{data_digest} . "\r\n";
+	print "Last-Modified: " . strftime("%a, %d %b %Y %H:%M:%S %Z", 
+			gmtime(time)) . "\r\n";
 
 	# Send Content-Type header
 	print "Content-Type: text/html; charset=ISO-8859-1\r\n";
-	#	print "Last-Modified: " . strftime("%a, %d %b %Y %H:%M:%S %Z", 
-	#		gmtime(time)) . "\r\n";
 	print "\r\n";
 
 	# And the page data
@@ -343,6 +347,8 @@
 	if (! -e $docroot . $path) {
 		# File doesn't exist
 		$cache{$docroot . $path}{data} = $data;
+		$cache{$docroot . $path}{data_digest} = 
+				'"' . md5_base64($data) . '"';
 		$cache{$docroot . $path}{data_last_modified} = time;
 		return;
 	}
@@ -479,6 +485,7 @@
 
 	# Save generated page data in cache
 	$$cacheentry{data} = $data;
+	$$cacheentry{data_digest} = '"' . md5_base64{$data} . '"';
 	$$cacheentry{data_last_modified} = time;
 }
 
@@ -494,6 +501,8 @@
 	if (! -e $docroot . $path) {
 		# File doesn't exist
 		$cache{$docroot . $path}{data} = "";
+		$cache{$docroot . $path}{data_digest} = 
+				'"' . md5_base64("") . '"';
 		$cache{$docroot . $path}{data_last_modified} = time;
 		return;
 	}
@@ -559,6 +568,7 @@
 
 	# Update document cache
 	$cache{$docroot . $path}{data} = $data;
+	$cache{$docroot . $path}{data_digest} = '"' . md5_base64($data) . '"';
 	$cache{$docroot . $path}{data_last_modified} = time;
 }
 
@@ -595,4 +605,3 @@
 	# Otherwise, the cached data is valid
 }
 
-




More information about the netsurf-commits mailing list