Class: OMF::Web::Rack::MultiFile
- Inherits:
-
Rack::File
- Object
- Rack::File
- OMF::Web::Rack::MultiFile
- Defined in:
- lib/omf-web/rack/multi_file.rb
Overview
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
.
Instance Method Summary collapse
- #_call(env) ⇒ Object
-
#initialize(roots, cache_control = nil) ⇒ MultiFile
constructor
A new instance of MultiFile.
Constructor Details
#initialize(roots, cache_control = nil) ⇒ MultiFile
Returns a new instance of MultiFile.
13 14 15 16 |
# File 'lib/omf-web/rack/multi_file.rb', line 13 def initialize(roots, cache_control = nil) super nil, cache_control @roots = roots end |
Instance Method Details
#_call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/omf-web/rack/multi_file.rb', line 18 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 |