Parent

Methods

Unicorn::App::OldRails::Static

Static file handler for Rails < 2.3. This handler is only provided as a convenience for developers. Performance-minded deployments should use nginx (or similar) for serving static files.

This supports page caching directly and will try to resolve a request in the following order:

This means that if you are using page caching it will actually work with Unicorn and you should see a decent speed boost (but not as fast as if you use a static server like nginx).

Constants

FILE_METHODS
PATH_INFO
REQUEST_METHOD

avoid allocating new strings for hash lookups

REQUEST_URI

Public Class Methods

new(app) click to toggle source
# File lib/unicorn/app/old_rails/static.rb, line 30
def initialize(app)
  self.app = app
  self.root = "#{::RAILS_ROOT}/public"
  self.file_server = ::Rack::File.new(root)
end

Public Instance Methods

call(env) click to toggle source
# File lib/unicorn/app/old_rails/static.rb, line 36
def call(env)
  # short circuit this ASAP if serving non-file methods
  FILE_METHODS.include?(env[REQUEST_METHOD]) or return app.call(env)

  # first try the path as-is
  path_info = env[PATH_INFO].chomp("/")
  if File.file?("#{root}/#{::Rack::Utils.unescape(path_info)}")
    # File exists as-is so serve it up
    env[PATH_INFO] = path_info
    return file_server.call(env)
  end

  # then try the cached version:
  path_info << ActionController::Base.page_cache_extension

  if File.file?("#{root}/#{::Rack::Utils.unescape(path_info)}")
    env[PATH_INFO] = path_info
    return file_server.call(env)
  end

  app.call(env) # call OldRails
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.