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-0.3.2 lib/orange-core/middleware/static_file.rb
orange-0.3.1 lib/orange-core/middleware/static_file.rb
orange-0.3.0 lib/orange-core/middleware/static_file.rb
orange-0.2.11 lib/orange-core/middleware/static_file.rb
orange-0.2.9 lib/orange-core/middleware/static_file.rb
orange-0.2.8 lib/orange-core/middleware/static_file.rb
orange-0.2.7 lib/orange-core/middleware/static_file.rb
orange-0.2.6 lib/orange-core/middleware/static_file.rb
orange-0.2.5 lib/orange-core/middleware/static_file.rb
orange-0.2.4 lib/orange-core/middleware/static_file.rb
orange-0.2.3 lib/orange-core/middleware/static_file.rb
orange-0.1.10 lib/orange-core/middleware/static_file.rb
orange-0.1.8 lib/orange-core/middleware/static_file.rb
orange-0.1.7 lib/orange-core/middleware/static_file.rb
orange-0.1.4 lib/orange-core/middleware/static_file.rb
orange-0.1.2 lib/orange-core/middleware/static_file.rb
orange-0.1.0 lib/orange-core/middleware/static_file.rb
orange-0.0.15 lib/orange-core/middleware/static_file.rb
orange-0.0.14 lib/orange-core/middleware/static_file.rb
orange-0.0.13 lib/orange/middleware/static_file.rb