Comparison

plugins/mod_httpserver.lua @ 635:25f1117d7886

Add initial mod_httpserver for serving static content
author Matthew Wild <mwild1@gmail.com>
date Mon, 22 Dec 2008 22:13:22 +0000
child 696:b35faad717f2
comparison
equal deleted inserted replaced
634:1af93ea23f96 635:25f1117d7886
1
2 local open = io.open;
3 local t_concat = table.concat;
4
5 local http_base = "www_files";
6
7 local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" };
8
9 local http_path = { http_base };
10 local function handle_request(method, body, request)
11 local path = request.url.path:gsub("%.%.%/", ""):gsub("^/[^/]+", "");
12 http_path[2] = path;
13 local f, err = open(t_concat(http_path), "r");
14 if not f then return response_404; end
15 local data = f:read("*a");
16 f:close();
17 return data;
18 end
19
20 httpserver.new{ port = 5280, base = "files", handler = handle_request, ssl = false}