Sha256: 0eea1a49c7bede01e7f708f4c38dee68c34b2ded643a89e9fd7d0695f5398346

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'evma_httpserver'
require 'socket'

module Noder
  module HTTP
    class Connection < EM::Connection
      include EventMachine::HttpServer

      attr_accessor :app, :environment, :request_stack, :settings

      def initialize(*args)
        super(*args)
        @settings = args[1]
      end
      
      def post_init
        super
        if settings[:enable_ssl]
          start_tls(:private_key_file => settings[:ssl_key], :cert_chain_file => settings[:ssl_cert], :verify_peer => false)
        end
      end

      def process_http_request
        env = {
          connection: self,
          request_env: request_env,
          request: nil,
          response: nil
        }
        EM.defer do
          request_stack.call(env)
        end
      end

      def request_env
        port, ip = Socket.unpack_sockaddr_in(get_peername)
        {
          request_method: @http_request_method,
          cookie: @http_cookie,
          content_type: @http_content_type,
          path_info: @http_path_info,
          request_uri: @http_request_uri,
          query_string: @http_query_string,
          post_content: @http_post_content,
          headers: @http_headers,
          protocol: @http_protocol,
          ip: ip
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
noder-0.0.2 lib/noder/http/connection.rb