File tree Expand file tree Collapse file tree 6 files changed +35
-42
lines changed
Expand file tree Collapse file tree 6 files changed +35
-42
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 22$: << File . dirname ( __FILE__ ) +'/../../lib'
33require 'goliath'
44require 'postrank-uri'
5- require File . dirname ( __FILE__ ) +'/../favicon'
65
76# Install phantomjs: http://code.google.com/p/phantomjs/wiki/QuickStart
87# $> ruby rasterize.rb -sv
98# $> curl http://localhost:9000/?url=http://www.google.com (or rather, visit in the browser!)
109
1110class Rasterize < Goliath ::API
1211use Goliath ::Rack ::Params
13- use Favicon , File . expand_path ( File . dirname ( __FILE__ ) +"/../public/favicon.ico" )
12+ use Goliath :: Rack :: Favicon , File . expand_path ( File . dirname ( __FILE__ ) +"/../public/favicon.ico" )
1413use Goliath ::Rack ::Validation ::RequestMethod , %w( GET )
1514use Goliath ::Rack ::Validation ::RequiredParam , { :key => 'url' }
1615
Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ def response(env)
3737end
3838
3939class Websocket < Goliath ::API
40+ use Goliath ::Rack ::Favicon , File . expand_path ( File . dirname ( __FILE__ ) + '/ws/favicon.ico' )
41+
4042get '/' , WSInfo
4143map '/ws' , WebsocketEndPoint
4244end
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ module Rack
66autoload :Builder , 'goliath/rack/builder'
77autoload :DefaultMimeType , 'goliath/rack/default_mime_type'
88autoload :DefaultResponseFormat , 'goliath/rack/default_response_format'
9+ autoload :Favicon , 'goliath/rack/favicon'
910autoload :Formatters , 'goliath/rack/formatters'
1011autoload :Heartbeat , 'goliath/rack/heartbeat'
1112autoload :JSONP , 'goliath/rack/jsonp'
Original file line number Diff line number Diff line change 1+ require 'time'
2+
3+ # Reads a favicon.ico statically at load time, renders it on any request for
4+ # '/favicon.ico', and sends every other request on downstream.
5+ #
6+ # Rack::Static is a better option if you're serving several static assets.
7+ #
8+ module Goliath
9+ module Rack
10+ class Favicon
11+ def initialize ( app , filename )
12+ @app = app
13+ @favicon = File . read ( File . join ( filename ) )
14+ @expires = Time . at ( Time . now + ( 60 * 60 * 24 * 7 ) ) . utc . rfc822 . to_s
15+ @last_modified = File . mtime ( filename ) . utc . rfc822 . to_s
16+ end
17+
18+ def call ( env )
19+ if env [ 'REQUEST_PATH' ] == '/favicon.ico'
20+ env . logger . info ( 'Serving favicon.ico' )
21+
22+ [ 200 , { 'Last-Modified' => @last_mod ,
23+ 'Expires' => @expires ,
24+ 'Content-Type' => "image/vnd.microsoft.icon" } , @favicon ]
25+ else
26+ @app . call ( env )
27+ end
28+ end
29+ end
30+ end
31+ end
You can’t perform that action at this time.
0 commit comments