Class: Hercules::HttpHandler
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Hercules::HttpHandler
- Includes:
- EventMachine::HttpServer
- Defined in:
- lib/http_handler.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ HttpHandler
constructor
A new instance of HttpHandler.
- #process_http_request ⇒ Object
- #send(resp, status, message) ⇒ Object
Constructor Details
#initialize(*args) ⇒ HttpHandler
Returns a new instance of HttpHandler.
13 14 15 16 |
# File 'lib/http_handler.rb', line 13 def initialize *args @config = args[0][:config] @log = args[0][:log] end |
Instance Method Details
#process_http_request ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/http_handler.rb', line 18 def process_http_request begin @config.reload resp = EventMachine::DelegatedHttpResponse.new( self ) # Block which fulfills the request if @http_request_method == "GET" req = RequestHandler.new({:config => @config, :log => @log, :method => @http_request_method, :path => @http_path_info, :query => @http_query_string, :body => @http_post_content}) req.run resp.status = req.status resp.content = req. resp.send_response else req = RequestHandler.new({:config => @config, :log => @log, :method => @http_request_method, :path => @http_path_info, :query => @http_query_string, :body => @http_post_content}) req.run resp.content = "Deploy queued" resp.send_response end rescue Exception => e send(resp, 500, "Error while processing HTTP request: #{e.inspect} \nREQUEST: #{@http_request_method} #{@http_path_info}?#{@http_query_string}\n#{@http_post_content}") @log.error "Backtrace: #{e.backtrace}" end end |
#send(resp, status, message) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/http_handler.rb', line 41 def send resp, status, if status == 500 @log.error "#{status}: #{}" end resp.status = status resp.content = resp.send_response end |