Comparison

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
comparison
equal deleted inserted replaced
5233:342c46e62f50 5234:a9f0a1becc66
31 local orig_path = request.path; 31 local orig_path = request.path;
32 local full_path = http_base.."/"..path; 32 local full_path = http_base.."/"..path;
33 local attr = stat(full_path); 33 local attr = stat(full_path);
34 if not attr then 34 if not attr then
35 return 404; 35 return 404;
36 end
37
38
39 local tag = ("%02x-%x-%x-%x"):format(attr.dev or 0, attr.ino or 0, attr.size or 0, attr.modification or 0);
40 response.headers.etag = tag;
41 if tag == request.headers.if_none_match then
42 return 304;
36 end 43 end
37 44
38 if attr.mode == "directory" then 45 if attr.mode == "directory" then
39 if full_path:sub(-1) ~= "/" then 46 if full_path:sub(-1) ~= "/" then
40 response.headers.location = orig_path.."/"; 47 response.headers.location = orig_path.."/";