Diff

plugins/mod_http_files.lua @ 5234:a9f0a1becc66

mod_http_files: Add ETag and check If-None-Match to allow client-side cache
author Kim Alvefur <zash@zash.se>
date Tue, 11 Dec 2012 22:30:13 +0100
parent 5233:342c46e62f50
child 5235:e0373e0dd048
line wrap: on
line diff
--- a/plugins/mod_http_files.lua	Tue Dec 11 22:26:41 2012 +0100
+++ b/plugins/mod_http_files.lua	Tue Dec 11 22:30:13 2012 +0100
@@ -35,6 +35,13 @@
 		return 404;
 	end
 
+
+	local tag = ("%02x-%x-%x-%x"):format(attr.dev or 0, attr.ino or 0, attr.size or 0, attr.modification or 0);
+	response.headers.etag = tag;
+	if tag == request.headers.if_none_match then
+		return 304;
+	end
+
 	if attr.mode == "directory" then
 		if full_path:sub(-1) ~= "/" then
 			response.headers.location = orig_path.."/";