comparison plugins/mod_http_files.lua @ 5249:d1baef49be21

Merge 0.9->trunk
author Kim Alvefur <zash@zash.se>
date Sun, 16 Dec 2012 08:37:14 +0100
parents 13553f4132a8
children 6209b9a0244b
comparison
equal deleted inserted replaced
5246:eba55873ef29 5249:d1baef49be21
55 local attr = stat(full_path); 55 local attr = stat(full_path);
56 if not attr then 56 if not attr then
57 return 404; 57 return 404;
58 end 58 end
59 59
60 response.headers.last_modified = os_date('!%a, %d %b %Y %H:%M:%S GMT', attr.modification); 60 local last_modified = os_date('!%a, %d %b %Y %H:%M:%S GMT', attr.modification);
61 response.headers.last_modified = last_modified;
61 62
62 local tag = ("%02x-%x-%x-%x"):format(attr.dev or 0, attr.ino or 0, attr.size or 0, attr.modification or 0); 63 local etag = ("%02x-%x-%x-%x"):format(attr.dev or 0, attr.ino or 0, attr.size or 0, attr.modification or 0);
63 response.headers.etag = tag; 64 response.headers.etag = etag;
64 if tag == request.headers.if_none_match then 65
66 if etag == request.headers.if_none_match
67 or last_modified == request.headers.if_modified_since then
65 return 304; 68 return 304;
66 end 69 end
67 70
68 local data = cache[path]; 71 local data = cache[path];
69 if data then 72 if data then
96 :tag("a", { href = file }):text(file) 99 :tag("a", { href = file }):text(file)
97 :up():up(); 100 :up():up();
98 end 101 end
99 end 102 end
100 data = "<!DOCTYPE html>\n"..tostring(html); 103 data = "<!DOCTYPE html>\n"..tostring(html);
101 cache[path] = { data = html, content_type = mime_map.html; hits = 0 }; 104 cache[path] = { data = data, content_type = mime_map.html; hits = 0 };
102 response.headers.content_type = mime_map.html; 105 response.headers.content_type = mime_map.html;
103 end 106 end
104 107
105 else 108 else
106 local f = open(full_path, "rb"); 109 local f = open(full_path, "rb");