class Rack::IndexFile

Constants

F

Public Class Methods

new(root, headers={}, default_mime = 'text/plain') click to toggle source
# File lib/rack/index_file.rb, line 8
def initialize(root, headers={}, default_mime = 'text/plain')
  @path = root
end

Public Instance Methods

_call(env) click to toggle source
# File lib/rack/index_file.rb, line 12
def _call(env)
  unless ALLOWED_VERBS.include? env[REQUEST_METHOD]
    return fail(405, "Method Not Allowed", {'Allow' => ALLOW_HEADER})
  end

  available = begin
    F.file?(@path) && F.readable?(@path)
  rescue SystemCallError
    false
  end

  if available
    serving(env)
  else
    fail(404, "File not found: #{path_info}")
  end
end