Class | Rack::File |
In: |
lib/rack/file.rb
|
Parent: | Object |
Rack::File serves files below the root given, according to the path info of the Rack request.
Handlers can detect if bodies are a Rack::File, and use mechanisms like sendfile on the path.
F | = | ::File |
path | [RW] | |
root | [RW] |
# File lib/rack/file.rb, line 22 22: def _call(env) 23: if env["PATH_INFO"].include? ".." 24: return [403, {"Content-Type" => "text/plain"}, ["Forbidden\n"]] 25: end 26: 27: @path = F.join(@root, env["PATH_INFO"]) 28: ext = F.extname(@path)[1..-1] 29: 30: if F.file?(@path) && F.readable?(@path) 31: [200, { 32: "Content-Type" => MIME_TYPES[ext] || "text/plain", 33: "Content-Length" => F.size(@path).to_s 34: }, self] 35: else 36: return [404, {"Content-Type" => "text/plain"}, 37: ["File not found: #{env["PATH_INFO"]}\n"]] 38: end 39: end