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.0.12 lib/orange/middleware/static_file.rb
orange-0.0.10 lib/orange/middleware/static_file.rb
orange-0.0.8 lib/orange/middleware/static_file.rb
orange-0.0.7 lib/orange/middleware/static_file.rb
orange-0.0.6 lib/orange/middleware/static_file.rb
orange-0.0.5 lib/orange/middleware/static_file.rb
orange-0.0.4 lib/orange/middleware/static_file.rb
orange-0.0.3 lib/orange/middleware/static_file.rb
orange-0.0.2 lib/orange/middleware/static_file.rb