Class: Rack::IndexFile

Inherits:
File
  • Object
show all
Defined in:
lib/rack/index_file.rb

Constant Summary collapse

F =
::File

Instance Method Summary collapse

Constructor Details

#initialize(root, headers = {}, default_mime = 'text/plain') ⇒ IndexFile

Returns a new instance of IndexFile.



8
9
10
# File 'lib/rack/index_file.rb', line 8

def initialize(root, headers={}, default_mime = 'text/plain')
  @path = root
end

Instance Method Details

#_call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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