Class: Goliath::Rack::Favicon

Inherits:
Object
  • Object
show all
Defined in:
lib/goliath/rack/favicon.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, filename) ⇒ Favicon

Returns a new instance of Favicon.



11
12
13
14
15
16
# File 'lib/goliath/rack/favicon.rb', line 11

def initialize(app, filename)
  @app = app
  @favicon = File.read(File.join(filename))
  @expires  = Time.at(Time.now + (60 * 60 * 24 * 7)).utc.rfc822.to_s
  @last_modified = File.mtime(filename).utc.rfc822.to_s
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/goliath/rack/favicon.rb', line 18

def call(env)
  if env['REQUEST_PATH'] == '/favicon.ico'
    env.logger.info('Serving favicon.ico')

    [200, {'Last-Modified' => @last_modified,
           'Expires' => @expires,
           'Content-Type' => "image/vnd.microsoft.icon"}, @favicon]
  else
    @app.call(env)
  end
end