Class: Noder::HTTP::Connection

Inherits:
EM::Connection
  • Object
show all
Includes:
EventMachine::HttpServer
Defined in:
lib/noder/http/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Connection

Returns a new instance of Connection.



11
12
13
14
# File 'lib/noder/http/connection.rb', line 11

def initialize(*args)
  super(*args)
  @settings = args[1]
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



9
10
11
# File 'lib/noder/http/connection.rb', line 9

def app
  @app
end

#environmentObject

Returns the value of attribute environment.



9
10
11
# File 'lib/noder/http/connection.rb', line 9

def environment
  @environment
end

#request_stackObject

Returns the value of attribute request_stack.



9
10
11
# File 'lib/noder/http/connection.rb', line 9

def request_stack
  @request_stack
end

#settingsObject

Returns the value of attribute settings.



9
10
11
# File 'lib/noder/http/connection.rb', line 9

def settings
  @settings
end

Instance Method Details

#post_initObject



16
17
18
19
20
21
# File 'lib/noder/http/connection.rb', line 16

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

#process_http_requestObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/noder/http/connection.rb', line 23

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

#request_envObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/noder/http/connection.rb', line 35

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