Sha256: 2f2ef7e17a9b8ac14546505e0f3793d76f5a2dbbc3e098e4012c355cf8dc804e

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

# coding: utf-8

require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
require 'json'
require File.dirname(__FILE__) + '/request_handler'

module Hercules
  class HttpHandler < EventMachine::Connection
    include EventMachine::HttpServer

    def initialize *args
      @config = args[0][:config]
      @log = args[0][:log]
    end

    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

    def send resp, status, message
      if status == 500
        @log.error "#{status}: #{message}"
      end
      resp.status = status
      resp.content = message
      resp.send_response
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hercules-0.2.6 lib/http_handler.rb
hercules-0.2.5 lib/http_handler.rb
hercules-0.2.4 lib/http_handler.rb
hercules-0.2.3 lib/http_handler.rb
hercules-0.2.2 lib/http_handler.rb