Class: Orange::Middleware::StaticFile
- Defined in:
- lib/orange-core/middleware/static_file.rb
Overview
Rack::File serves files below the root
given, according to the path info of the Rack request. Orange::Middleware::StaticFile acts the same as Rack::File, but acts on the orange specific path if available. (So site url would be ignored, etc.)
Handlers can detect if bodies are a Rack::File, and use mechanisms like sendfile on the path
.
Instance Method Summary collapse
Instance Method Details
#_call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/orange-core/middleware/static_file.rb', line 14 def _call(env) @path_info = Rack::Utils.unescape(env['orange.env']["route.path"]) || Rack::Utils.unescape(env["PATH_INFO"]) @root = env['orange.env']['file.root'] || @root return forbidden if @path_info.include? ".." @path = F.join(@root, @path_info) begin if F.file?(@path) && F.readable?(@path) serving else raise Errno::EPERM end rescue SystemCallError not_found end end |