Sha256: 04d5284ce67d8ed96120527868acb49b24e817ded68e269018181ef3ee61a246

Contents?: true

Size: 952 Bytes

Versions: 49

Compression:

Stored size: 952 Bytes

Contents

require 'rack'
require 'rack/utils'

module Orange::Middleware
  # 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+.

  class StaticFile < Rack::File
    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
  end
end

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
orange-core-0.7.1 lib/orange-core/middleware/static_file.rb
orange-core-0.7.0 lib/orange-core/middleware/static_file.rb
orange-core-0.6.0 lib/orange-core/middleware/static_file.rb
orange-core-0.5.9 lib/orange-core/middleware/static_file.rb
orange-core-0.5.8 lib/orange-core/middleware/static_file.rb
orange-core-0.5.5 lib/orange-core/middleware/static_file.rb
orange-core-0.5.3 lib/orange-core/middleware/static_file.rb
orange-0.5.5 lib/orange-core/middleware/static_file.rb
orange-0.5.4 lib/orange-core/middleware/static_file.rb
orange-0.5.3 lib/orange-core/middleware/static_file.rb
orange-0.5.2 lib/orange-core/middleware/static_file.rb
orange-0.5.1 lib/orange-core/middleware/static_file.rb
orange-0.4.0 lib/orange-core/middleware/static_file.rb
orange-0.3.9 lib/orange-core/middleware/static_file.rb
orange-0.3.8 lib/orange-core/middleware/static_file.rb
orange-0.3.7 lib/orange-core/middleware/static_file.rb
orange-0.3.6 lib/orange-core/middleware/static_file.rb
orange-0.3.5 lib/orange-core/middleware/static_file.rb
orange-0.3.4 lib/orange-core/middleware/static_file.rb
orange-0.3.3 lib/orange-core/middleware/static_file.rb