Class: DripDrop::HTTPServerHandler

Inherits:
BaseHandler show all
Defined in:
lib/dripdrop/handlers/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, opts = {}) ⇒ HTTPServerHandler

Returns a new instance of HTTPServerHandler.



62
63
64
65
66
# File 'lib/dripdrop/handlers/http.rb', line 62

def initialize(uri,opts={})
  @uri     = uri
  @address = uri.to_s
  @opts    = opts
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



60
61
62
# File 'lib/dripdrop/handlers/http.rb', line 60

def address
  @address
end

#optsObject (readonly)

Returns the value of attribute opts.



60
61
62
# File 'lib/dripdrop/handlers/http.rb', line 60

def opts
  @opts
end

Instance Method Details

#on_recv(msg_format = :dripdrop_json, &block) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dripdrop/handlers/http.rb', line 68

def on_recv(msg_format=:dripdrop_json,&block)
  #Thin's error handling only rescues stuff w/o a backtrace
  begin
    Thin::Logging.silent = true
     
    uri_path = @uri.path.empty? ? '/' : @uri.path
     
    Thin::Server.start(@uri.host, @uri.port) do
      map uri_path do
        run HTTPApp.new(msg_format,&block)
      end
    end
  rescue Exception => e
    $stderr.write "Error in Thin server: #{e.message}\n#{e.backtrace.join("\n")}"
  end
end