Class: Innate::RackFileWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/innate/rack_file_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, cache_control = nil) ⇒ RackFileWrapper

Returns a new instance of RackFileWrapper.



3
4
5
# File 'lib/innate/rack_file_wrapper.rb', line 3

def initialize(root, cache_control = nil)
  @file = Rack::File.new(root, cache_control)
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/innate/rack_file_wrapper.rb', line 7

def call(env)
  status, header, body = @file.call(env)

  if status == 403
    unless Rack::File::ALLOWED_VERBS.include?(env['REQUEST_METHOD'])
      body = "File not Found: #{Rack::Utils.unescape(env['PATH_INFO'])}\n"
      return 404, {
        'Content-Type' => 'text/plain',
        'Content-Length' => body.size,
        'X-Cascade' => 'pass',
      }, [body]
    end
  end

  return status, header, body
end