forked from postrank-labs/goliath
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a favicon interceptor to the examples, and used it in the raste…
…rizer examples
- Loading branch information
Philip (flip) Kromer
committed
Jul 31, 2011
1 parent
88e6748
commit 6395370
Showing
5 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env ruby | ||
require 'time' | ||
|
||
# | ||
# Reads a favicon.ico statically at load time, renders it on any request for | ||
# '/favicon.ico', and sends every other request on downstream. | ||
# | ||
# If you will be serving even one more file than this one, you should instead | ||
# use Rack::Static: | ||
# | ||
# use(Rack::Static, # render static files from ./public | ||
# :root => Goliath::Application.app_path("public"), | ||
# :urls => ["/favicon.ico", '/stylesheets', '/javascripts', '/images']) | ||
# | ||
class Favicon | ||
def initialize(app, filename) | ||
@@favicon = File.read(filename) | ||
@@last_mod = File.mtime(filename).utc.rfc822 | ||
@@expires = Time.at(Time.now + 604800).utc.rfc822 # 1 week from now | ||
@app = app | ||
end | ||
|
||
def call(env, *args) | ||
if env['REQUEST_PATH'] == '/favicon.ico' | ||
return [200, {"Last-Modified"=> @@last_mod.to_s, "Expires" => @@expires, "Content-Type"=>"image/vnd.microsoft.icon"}, @@favicon] | ||
else | ||
return @app.call(env) | ||
end | ||
end | ||
end | ||
|
||
if File.expand_path($0) == File.expand_path(__FILE__) | ||
$:<< '../lib' << 'lib' | ||
require 'goliath' | ||
puts "starting hello world!" | ||
class HelloWorld < Goliath::API | ||
HelloWorld.use(Favicon, File.expand_path(File.dirname(__FILE__)+"/public/favicon.ico")) | ||
end | ||
require(File.dirname(__FILE__)+'/hello_world.rb') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters