Changeset

5253:ad45612199e0

mod_http_files: Avoid a bunch of table lookups
author Kim Alvefur <zash@zash.se>
date Fri, 21 Dec 2012 08:14:33 +0100
parents 5252:6209b9a0244b
children 5254:df3552822054
files plugins/mod_http_files.lua
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_http_files.lua	Fri Dec 21 08:10:07 2012 +0100
+++ b/plugins/mod_http_files.lua	Fri Dec 21 08:14:33 2012 +0100
@@ -57,24 +57,28 @@
 		return 404;
 	end
 
+	local request_headers, response_headers = request.headers, response.headers;
+
 	local last_modified = os_date('!%a, %d %b %Y %H:%M:%S GMT', attr.modification);
-	response.headers.last_modified = last_modified;
+	response_headers.last_modified = last_modified;
 
 	local etag = ("%02x-%x-%x-%x"):format(attr.dev or 0, attr.ino or 0, attr.size or 0, attr.modification or 0);
-	response.headers.etag = etag;
+	response_headers.etag = etag;
 
-	if etag == request.headers.if_none_match
-	or last_modified == request.headers.if_modified_since then
+	local if_none_match = request_headers.if_none_match
+	local if_modified_since = request_headers.if_modified_since;
+	if etag == if_none_match
+	or last_modified == if_modified_since then
 		return 304;
 	end
 
 	local data = cache[path];
 	if data then
-		response.headers.content_type = data.content_type;
+		response_headers.content_type = data.content_type;
 		data = data.data;
 	elseif attr.mode == "directory" then
 		if full_path:sub(-1) ~= "/" then
-			response.headers.location = orig_path.."/";
+			response_headers.location = orig_path.."/";
 			return 301;
 		end
 		for i=1,#dir_indices do
@@ -102,7 +106,7 @@
 			end
 			data = "<!DOCTYPE html>\n"..tostring(html);
 			cache[path] = { data = data, content_type = mime_map.html; hits = 0 };
-			response.headers.content_type = mime_map.html;
+			response_headers.content_type = mime_map.html;
 		end
 
 	else
@@ -117,7 +121,7 @@
 		local ext = path:match("%.([^.]*)$");
 		local content_type = mime_map[ext];
 		cache[path] = { data = data; content_type = content_type; };
-		response.headers.content_type = content_type;
+		response_headers.content_type = content_type;
 	end
 
 	return response:send(data);