22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/rascut/httpd.rb', line 22
def _call(env)
if env["PATH_INFO"].include? ".."
return [403, {"Content-Type" => "text/plain"}, ["Forbidden\n"]]
end
@path = env["PATH_INFO"] == '/' ? @root : F.join(@root, env['PATH_INFO'])
ext = F.extname(@path)[1..-1]
if F.file?(@path) && F.readable?(@path)
[200, {
"Content-Type" => MIME_TYPES[ext] || "text/plain",
"Content-Length" => F.size(@path).to_s
}, self]
else
return [404, {"Content-Type" => "text/plain"},
["File not found: #{env["PATH_INFO"]}\n"]]
end
end
|