blob: 1f3e9480206019644abb5cbe5f7d7004fedf998f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
module("luci.httpd.FileHandler", package.seeall)
require("luci.util")
require("luci.fs")
require("ltn12")
SimpleHandler = luci.util.class(luci.httpd.Handler)
function SimpleHandler.__init__(self, docroot)
luci.httpd.Handler.__init__(self)
self.docroot = docroot
end
function SimpleHandler.handle(self, request)
local response = luci.httpd.Response()
local f = self.docroot .. "/" .. request.request_uri:gsub("%.%./", "")
request.error:write("Requested " .. f .. "\n")
local s = luci.fs.stat(f, "size")
if s then
response:addheader("Content-Length", s)
response:setsource(ltn12.source.file(io.open(f)))
else
response:setstatus(404)
end
end
|