2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
10 local httpserver = require "net.httpserver";
13 local t_concat = table.concat;
14 local check_http_path;
16 local http_base = config.get("*", "core", "http_path") or "www_files";
18 local response_403 = { status = "403 Forbidden", body = "<h1>Invalid URL</h1>Sorry, we couldn't find what you were looking for :(" };
19 local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" };
21 local http_path = { http_base };
22 local function handle_request(method, body, request)
23 local path = check_http_path(request.url.path:gsub("^/[^/]+%.*", ""));
28 local f, err = open(t_concat(http_path), "r");
29 if not f then return response_404; end
30 local data = f:read("*a");
35 local ports = config.get(module.host, "core", "http_ports") or { 5280 };
36 httpserver.new_from_config(ports, "files", handle_request);
38 function check_http_path(url)
39 if url:sub(1,1) ~= "/" then
44 for part in url:gmatch("%/([^/]+)") do
47 elseif part ~= "." then