Class: Hercules::HttpHandler

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
EventMachine::HttpServer
Defined in:
lib/http_handler.rb

Instance Method Summary collapse

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_requestObject



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.message
      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, message
  if status == 500
    @log.error "#{status}: #{message}"
  end
  resp.status = status
  resp.content = message
  resp.send_response
end