Class: RFlow::Components::HTTP::Server::Connection
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- RFlow::Components::HTTP::Server::Connection
- Includes:
- EventMachine::HttpServer
- Defined in:
- lib/rflow/components/http/server.rb
Instance Attribute Summary collapse
-
#client_ip ⇒ Object
readonly
Returns the value of attribute client_ip.
-
#client_port ⇒ Object
readonly
Returns the value of attribute client_port.
-
#server ⇒ Object
Returns the value of attribute server.
-
#server_ip ⇒ Object
readonly
Returns the value of attribute server_ip.
-
#server_port ⇒ Object
readonly
Returns the value of attribute server_port.
Instance Method Summary collapse
- #post_init ⇒ Object
- #process_http_request ⇒ Object
- #receive_data(data) ⇒ Object
- #send_http_response(response_message = nil) ⇒ Object
-
#unbind(reason = nil) ⇒ Object
Called when a connection is torn down for whatever reason.
Instance Attribute Details
#client_ip ⇒ Object (readonly)
Returns the value of attribute client_ip.
56 57 58 |
# File 'lib/rflow/components/http/server.rb', line 56 def client_ip @client_ip end |
#client_port ⇒ Object (readonly)
Returns the value of attribute client_port.
56 57 58 |
# File 'lib/rflow/components/http/server.rb', line 56 def client_port @client_port end |
#server ⇒ Object
Returns the value of attribute server.
55 56 57 |
# File 'lib/rflow/components/http/server.rb', line 55 def server @server end |
#server_ip ⇒ Object (readonly)
Returns the value of attribute server_ip.
56 57 58 |
# File 'lib/rflow/components/http/server.rb', line 56 def server_ip @server_ip end |
#server_port ⇒ Object (readonly)
Returns the value of attribute server_port.
56 57 58 |
# File 'lib/rflow/components/http/server.rb', line 56 def server_port @server_port end |
Instance Method Details
#post_init ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/rflow/components/http/server.rb', line 58 def post_init @client_port, @client_ip = Socket.unpack_sockaddr_in(get_peername) rescue ["?", "?.?.?.?"] @server_port, @server_ip = Socket.unpack_sockaddr_in(get_sockname) rescue ["?", "?.?.?.?"] RFlow.logger.debug "Connection from #{@client_ip}:#{@client_port} to #{@server_ip}:#{@server_port}" super no_environment_strings end |
#process_http_request ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rflow/components/http/server.rb', line 73 def process_http_request RFlow.logger.debug "Received a HTTP request from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port}" processing_event = RFlow::Message::ProcessingEvent.new(server.instance_uuid, Time.now.utc) = RFlow::Message.new('RFlow::Message::Data::HTTP::Request') .data.uri = @http_request_uri processing_event.context = signature processing_event.completed_at = Time.now.utc .provenance << processing_event server.request_port. end |
#receive_data(data) ⇒ Object
67 68 69 70 |
# File 'lib/rflow/components/http/server.rb', line 67 def receive_data(data) RFlow.logger.debug "Received #{data.bytesize} bytes of data from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port}" super end |
#send_http_response(response_message = nil) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rflow/components/http/server.rb', line 89 def send_http_response(=nil) RFlow.logger.debug "Sending an HTTP response to #{client_ip}:#{client_port}" resp = EventMachine::DelegatedHttpResponse.new(self) # Default values resp.status = 200 resp.content = "" resp.headers["Content-Type"] = "text/html" resp.headers["Server"] = "Apache" if resp.status = .data.status_code resp.content = .data.content .data.headers.each do |header, value| resp[headers] = value end end resp.send_response close_connection_after_writing end |
#unbind(reason = nil) ⇒ Object
Called when a connection is torn down for whatever reason. Remove this connection from the server’s list
114 115 116 117 |
# File 'lib/rflow/components/http/server.rb', line 114 def unbind(reason=nil) RFlow.logger.debug "Disconnected from HTTP client #{client_ip}:#{client_port} due to '#{reason}'" server.connections.delete(self.signature) end |