Method: Merb::Rack::Static#call

Defined in:
lib/merb-core/rack/middleware/static.rb

#call(env) ⇒ Object

:api: plugin



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/merb-core/rack/middleware/static.rb', line 12

def call(env)        
  path = if env[Merb::Const::PATH_INFO]
           env[Merb::Const::PATH_INFO].chomp(Merb::Const::SLASH)
         else
           Merb::Const::EMPTY_STRING
         end
  cached_path = (path.empty? ? 'index' : path) + '.html'
  
  if file_exist?(path) && env[Merb::Const::REQUEST_METHOD] =~ /GET|HEAD/ # Serve the file if it's there and the request method is GET or HEAD
    serve_static(env)
  elsif file_exist?(cached_path) && env[Merb::Const::REQUEST_METHOD] =~ /GET|HEAD/ # Serve the page cache if it's there and the request method is GET or HEAD
    env[Merb::Const::PATH_INFO] = cached_path
    serve_static(env)
  elsif path =~ /favicon\.ico/
    return [404, { Merb::Const::CONTENT_TYPE => Merb::Const::TEXT_SLASH_HTML }, "404 Not Found."]
  else
    @app.call(env)
  end
end