class Rack::Favicon

Constants

VERSION

Public Class Methods

new(app, options = {}) click to toggle source
# File lib/rack/favicon.rb, line 7
def initialize(app, options = {})
  @app     = app
  @options = options
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/favicon.rb, line 12
def call(env)
  status, headers, response = @app.call(env)

  if env['PATH_INFO'] =~ (/favicon\.ico$/)
    if @options[:image]
      path = ::File.join(Dir.getwd, @options[:image])
    else
      path = ::File.expand_path('../favicon.ico', __FILE__)
    end
    response = [ ::File.open(path, 'rb') { |file| file.read } ]
  end
  [status, headers, response]
end