Class: RFlow::Components::HTTP::Server
- Inherits:
-
RFlow::Component
- Object
- RFlow::Component
- RFlow::Components::HTTP::Server
- Defined in:
- lib/rflow/components/http/server.rb
Defined Under Namespace
Classes: ClosedConnection, Connection
Instance Attribute Summary collapse
-
#closed_connections ⇒ Object
Returns the value of attribute closed_connections.
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#listen ⇒ Object
Returns the value of attribute listen.
-
#port ⇒ Object
Returns the value of attribute port.
-
#proxy_real_client_ip_header ⇒ Object
Returns the value of attribute proxy_real_client_ip_header.
-
#proxy_real_client_port_header ⇒ Object
Returns the value of attribute proxy_real_client_port_header.
-
#proxy_real_server_ip_header ⇒ Object
Returns the value of attribute proxy_real_server_ip_header.
-
#proxy_real_server_port_header ⇒ Object
Returns the value of attribute proxy_real_server_port_header.
-
#server_signature ⇒ Object
Returns the value of attribute server_signature.
Instance Method Summary collapse
- #configure!(config) ⇒ Object
-
#process_message(input_port, input_port_key, connection, message) ⇒ Object
Getting all messages to response_port, which we need to filter for those that pertain to this component and have active connections.
- #run! ⇒ Object
Instance Attribute Details
#closed_connections ⇒ Object
Returns the value of attribute closed_connections.
12 13 14 |
# File 'lib/rflow/components/http/server.rb', line 12 def closed_connections @closed_connections end |
#connections ⇒ Object
Returns the value of attribute connections.
12 13 14 |
# File 'lib/rflow/components/http/server.rb', line 12 def connections @connections end |
#listen ⇒ Object
Returns the value of attribute listen.
12 13 14 |
# File 'lib/rflow/components/http/server.rb', line 12 def listen @listen end |
#port ⇒ Object
Returns the value of attribute port.
12 13 14 |
# File 'lib/rflow/components/http/server.rb', line 12 def port @port end |
#proxy_real_client_ip_header ⇒ Object
Returns the value of attribute proxy_real_client_ip_header.
12 13 14 |
# File 'lib/rflow/components/http/server.rb', line 12 def proxy_real_client_ip_header @proxy_real_client_ip_header end |
#proxy_real_client_port_header ⇒ Object
Returns the value of attribute proxy_real_client_port_header.
12 13 14 |
# File 'lib/rflow/components/http/server.rb', line 12 def proxy_real_client_port_header @proxy_real_client_port_header end |
#proxy_real_server_ip_header ⇒ Object
Returns the value of attribute proxy_real_server_ip_header.
12 13 14 |
# File 'lib/rflow/components/http/server.rb', line 12 def proxy_real_server_ip_header @proxy_real_server_ip_header end |
#proxy_real_server_port_header ⇒ Object
Returns the value of attribute proxy_real_server_port_header.
12 13 14 |
# File 'lib/rflow/components/http/server.rb', line 12 def proxy_real_server_port_header @proxy_real_server_port_header end |
#server_signature ⇒ Object
Returns the value of attribute server_signature.
12 13 14 |
# File 'lib/rflow/components/http/server.rb', line 12 def server_signature @server_signature end |
Instance Method Details
#configure!(config) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rflow/components/http/server.rb', line 16 def configure!(config) @listen = config['listen'] ? config['listen'] : '127.0.0.1' @port = config['port'] ? config['port'].to_i : 8000 @proxy_real_client_ip_header = config.has_key?('proxy-real-client-ip-header') ? config['proxy-real-client-ip-header'] : 'X-Real-IP' @proxy_real_client_port_header = config.has_key?('proxy-real-client-port-header') ? config['proxy-real-client-port-header'] : 'X-Real-Port' @proxy_real_server_ip_header = config.has_key?('proxy-real-server-ip-header') ? config['proxy-real-server-ip-header'] : 'X-Server-IP' @proxy_real_server_port_header = config.has_key?('proxy-real-server-port-header') ? config['proxy-real-server-port-header'] : 'X-Server-Port' @connections = {} @closed_connections = ActiveSupport::Cache::MemoryStore.new(expires_in: 5.minutes) end |
#process_message(input_port, input_port_key, connection, message) ⇒ Object
Getting all messages to response_port, which we need to filter for those that pertain to this component and have active connections. This is done by inspecting the provenance, specifically the context attribute that we stored originally
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rflow/components/http/server.rb', line 39 def (input_port, input_port_key, connection, ) return unless .data_type_name == 'RFlow::Message::Data::HTTP::Response' my_events = .provenance.find_all {|processing_event| processing_event.component_instance_uuid == uuid} my_events.each do |processing_event| connection_signature_string = processing_event.context.to_s if connections[connection_signature_string] connections[connection_signature_string].send_http_response else conn = closed_connections.read(connection_signature_string) if conn RFlow.logger.info "#{name}: Could not send HTTP response to #{conn.client_details}: connection is already closed" else RFlow.logger.info "#{name}: Could not send HTTP response to <client details expired>: connection is already closed" end end end end |
#run! ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/rflow/components/http/server.rb', line 27 def run! @server_signature = EM.start_server(@listen, @port, Connection) do |conn| conn.server = self self.connections[conn.signature.to_s] = conn RFlow.logger.debug { "#{name}: Connection from #{conn.client_details} to #{conn.server_details}" } end end |