+ local ext = path:match("%.([^.]*)$");
+ local mime = mime_map[ext];
+ if not mime then
+ mime = ext and "application/octet-stream" or "text/html";
+ end
+ module:log("warn", "ext: %s, mime: %s", ext, mime);
+ return {
+ headers = { ["Content-Type"] = mime; };
+ body = data;
+ };
+end
+
+local function handle_file_request(method, body, request)
+ local path = preprocess_path(request.url.path);
+ if not path then return response_400; end
+ path = path:gsub("^/[^/]+", ""); -- Strip /files/
+ return serve_file(path);
+end
+
+local function handle_default_request(method, body, request)
+ local path = preprocess_path(request.url.path);
+ if not path then return response_400; end
+ return serve_file(path);