Sha256: 533df330e6848d89d413757c93e37b43eca0321a58051e3d473fd528410dd9e8
Contents?: true
Size: 1.02 KB
Versions: 8
Compression:
Stored size: 1.02 KB
Contents
require 'rack/file' module OMF::Web::Rack # Rack::MultiFile serves files which it looks for below an array # of +roots+ directories 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+. # class MultiFile < ::Rack::File def initialize(roots, cache_control = nil) super nil, cache_control @roots = roots end def _call(env) @path_info = ::Rack::Utils.unescape(env["PATH_INFO"]) parts = @path_info.split SEPS return fail(403, "Forbidden") if parts.include? ".." @roots.each do |root| @path = F.join(root, *parts) #puts ">>>> CHECKING #{@path}" available = begin F.file?(@path) && F.readable?(@path) rescue SystemCallError false end if available return serving(env) end end fail(404, "File not found: #{@path_info}") end # _call end # MultiFile end # module
Version data entries
8 entries across 8 versions & 1 rubygems