Comparison

plugins/mod_http_files.lua @ 5235:e0373e0dd048

mod_http_files: Add Last-Modified header
author Kim Alvefur <zash@zash.se>
date Tue, 11 Dec 2012 22:30:50 +0100
parent 5234:a9f0a1becc66
child 5236:8d116a0cdacd
comparison
equal deleted inserted replaced
5234:a9f0a1becc66 5235:e0373e0dd048
7 -- 7 --
8 8
9 module:depends("http"); 9 module:depends("http");
10 local lfs = require "lfs"; 10 local lfs = require "lfs";
11 11
12 local os_date = os.date;
12 local open = io.open; 13 local open = io.open;
13 local stat = lfs.attributes; 14 local stat = lfs.attributes;
14 15
15 local http_base = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files")); 16 local http_base = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files"));
16 local dir_indices = module:get_option("http_files_index", { "index.html", "index.htm" }); 17 local dir_indices = module:get_option("http_files_index", { "index.html", "index.htm" });
33 local attr = stat(full_path); 34 local attr = stat(full_path);
34 if not attr then 35 if not attr then
35 return 404; 36 return 404;
36 end 37 end
37 38
39 response.headers.last_modified = os_date('!%a, %d %b %Y %H:%M:%S GMT', attr.modification);
38 40
39 local tag = ("%02x-%x-%x-%x"):format(attr.dev or 0, attr.ino or 0, attr.size or 0, attr.modification or 0); 41 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; 42 response.headers.etag = tag;
41 if tag == request.headers.if_none_match then 43 if tag == request.headers.if_none_match then
42 return 304; 44 return 304;