Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a favicon interceptor to the examples, and used it in the raste…

…rizer examples
  • Loading branch information...
commit 63953707f339eb5961d8d063902233afd533d0a0 1 parent 88e6748
Philip (flip) Kromer authored
View
1  README.md
@@ -93,3 +93,4 @@ Goliath has been in production at PostRank for over a year, serving a sustained
## License & Acknowledgments
Goliath is distributed under the MIT license, for full details please see the LICENSE file.
+Rock favicon CC-BY from [Douglas Feer](http://www.favicon.cc/?action=icon&file_id=375421)
View
40 examples/favicon.rb
@@ -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
View
3  examples/http_log.rb
@@ -56,6 +56,7 @@ def to_http_header(k)
# Write the request information into mongo
def record(process_time, resp, client_headers, response_headers)
e = env
+ e.trace('http_log_record')
EM.next_tick do
doc = {
request: {
@@ -81,4 +82,4 @@ def record(process_time, resp, client_headers, response_headers)
e.mongo.insert(doc)
end
end
-end
+end
View
BIN  examples/public/favicon.ico
Binary file not shown
View
3  examples/rasterize/rasterize.rb
@@ -2,6 +2,7 @@
$: << File.dirname(__FILE__)+'/../../lib'
require 'goliath'
require 'postrank-uri'
+require File.dirname(__FILE__)+'/../favicon'
# Install phantomjs: http://code.google.com/p/phantomjs/wiki/QuickStart
# $> ruby rasterize.rb -sv
@@ -9,7 +10,7 @@
class Rasterize < Goliath::API
use Goliath::Rack::Params
-
+ use Favicon, File.expand_path(File.dirname(__FILE__)+"/../public/favicon.ico")
use Goliath::Rack::Validation::RequestMethod, %w(GET)
use Goliath::Rack::Validation::RequiredParam, {:key => 'url'}
Please sign in to comment.
Something went wrong with that request. Please try again.