Comparison

plugins/mod_http_files.lua @ 5257:b125892e187c

mod_http_files: Escape paths in redirects
author Kim Alvefur <zash@zash.se>
date Fri, 21 Dec 2012 09:04:02 +0100
parent 5256:a77c6eba461e
child 5260:87f72452a893
comparison
equal deleted inserted replaced
5256:a77c6eba461e 5257:b125892e187c
10 local lfs = require "lfs"; 10 local lfs = require "lfs";
11 11
12 local os_date = os.date; 12 local os_date = os.date;
13 local open = io.open; 13 local open = io.open;
14 local stat = lfs.attributes; 14 local stat = lfs.attributes;
15 local build_path = require"socket.url".build_path;
15 16
16 local http_base = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files")); 17 local http_base = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files"));
17 local dir_indices = module:get_option("http_files_index", { "index.html", "index.htm" }); 18 local dir_indices = module:get_option("http_files_index", { "index.html", "index.htm" });
18 local show_file_list = module:get_option_boolean("http_files_show_list"); 19 local show_file_list = module:get_option_boolean("http_files_show_list");
19 20
76 if data and data.etag == etag then 77 if data and data.etag == etag then
77 response_headers.content_type = data.content_type; 78 response_headers.content_type = data.content_type;
78 data = data.data; 79 data = data.data;
79 elseif attr.mode == "directory" then 80 elseif attr.mode == "directory" then
80 if full_path:sub(-1) ~= "/" then 81 if full_path:sub(-1) ~= "/" then
81 response_headers.location = orig_path.."/"; 82 local path = { is_absolute = true, is_directory = true };
83 for dir in orig_path:gmatch("[^/]+") do path[#path+1]=dir; end
84 response_headers.location = build_path(path);
82 return 301; 85 return 301;
83 end 86 end
84 for i=1,#dir_indices do 87 for i=1,#dir_indices do
85 if stat(full_path..dir_indices[i], "mode") == "file" then 88 if stat(full_path..dir_indices[i], "mode") == "file" then
86 return serve_file(event, path..dir_indices[i]); 89 return serve_file(event, path..dir_indices[i]);