class Panoptimon::HTTP
Public Class Methods
new(args={})
click to toggle source
# File lib/panoptimon/http.rb, line 10 def initialize (args={}) @match = [] @mount = [] # TODO args[:config].http_port, ssl, etc @http = Thin::Server.new('0.0.0.0', 8080, self); end
Public Instance Methods
call(env)
click to toggle source
# File lib/panoptimon/http.rb, line 25 def call (env) path = env['PATH_INFO'] return favicon(env) if path == '/favicon.ico' # logger.debug { "#{path} => " + env.inspect } if go = @match.find {|x| path =~ x[0]} elsif go = @mount.find {|x| path =~ %r{^#{x[0]}(/|$)}} env['SCRIPT_NAME'] = go[0] env['PATH_INFO'] = path.sub(%r{^#{go[0]}}, '') else return [404, {'Content-Type' => 'text/html'}, '<html><head><title>Not Found</title></head>' + '<body><p>nope</p></body></html>'] end env['rack.logger'] = logger begin return go[1].call(env) rescue => ex logger.error { "error: #{ex.message} #{ex.backtrace.join("\n ")}" } return [500, {'Content-Type' => 'text/html'}, ['bah']] end end
favicon(env)
click to toggle source
# File lib/panoptimon/http.rb, line 47 def favicon(env) # TODO bundle / configure favicon? # NOTE why doesn't rack/thin support .to_path per spec? return [200, {'Content-Type' => 'image/x-icon'}, Pathname.new('/tmp/favicon.ico').open] end
hostport()
click to toggle source
# File lib/panoptimon/http.rb, line 21 def hostport "#{@http.host}:#{@http.port}" end
match(regexp, app)
click to toggle source
regexp-match
# File lib/panoptimon/http.rb, line 55 def match (regexp, app) regexp = %r{^#{regexp}} if regexp.class == String @match.push([regexp, app]) end
mount(point, app)
click to toggle source
path prefix
# File lib/panoptimon/http.rb, line 61 def mount (point, app) point.sub(%r{/*$}, '') @mount.push([point, app]) end
start()
click to toggle source
# File lib/panoptimon/http.rb, line 17 def start @http.backend.start end