rflow-components-http 0.0.3 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/lib/rflow/components/http/server.rb +15 -19
- data/lib/rflow/components/http/version.rb +1 -1
- data/spec/http_server_spec.rb +11 -0
- metadata +3 -1
data/Gemfile
CHANGED
@@ -31,20 +31,15 @@ class RFlow
|
|
31
31
|
# This is done by inspecting the provenance, specifically the
|
32
32
|
# context attribute that we stored originally
|
33
33
|
def process_message(input_port, input_port_key, connection, message)
|
34
|
-
RFlow.logger.debug "Received a message"
|
34
|
+
RFlow.logger.debug { "#{self.class.name}: Received a #{message.data_type_name}" }
|
35
35
|
return unless message.data_type_name == 'RFlow::Message::Data::HTTP::Response'
|
36
|
-
|
37
|
-
|
38
|
-
RFlow.logger.debug "Received a HTTP::Response message, determining if its mine"
|
39
36
|
my_events = message.provenance.find_all {|processing_event| processing_event.component_instance_uuid == instance_uuid}
|
40
|
-
|
41
|
-
# Attempt to send the data to each context match
|
37
|
+
|
42
38
|
my_events.each do |processing_event|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
connections[connection_signature].send_http_response message
|
39
|
+
connection_signature_string = processing_event.context.to_s
|
40
|
+
if connections[connection_signature_string]
|
41
|
+
RFlow.logger.debug { "#{self.class.name}: Found connection for #{connection_signature_string}" }
|
42
|
+
connections[connection_signature_string].send_http_response message
|
48
43
|
end
|
49
44
|
end
|
50
45
|
end
|
@@ -58,20 +53,20 @@ class RFlow
|
|
58
53
|
def post_init
|
59
54
|
@client_port, @client_ip = Socket.unpack_sockaddr_in(get_peername) rescue ["?", "?.?.?.?"]
|
60
55
|
@server_port, @server_ip = Socket.unpack_sockaddr_in(get_sockname) rescue ["?", "?.?.?.?"]
|
61
|
-
RFlow.logger.debug "Connection from #{@client_ip}:#{@client_port} to #{@server_ip}:#{@server_port}"
|
56
|
+
RFlow.logger.debug { "#{self.class.name}: Connection from #{@client_ip}:#{@client_port} to #{@server_ip}:#{@server_port}" }
|
62
57
|
super
|
63
58
|
no_environment_strings
|
64
59
|
end
|
65
60
|
|
66
61
|
|
67
62
|
def receive_data(data)
|
68
|
-
RFlow.logger.debug "Received #{data.bytesize} bytes of data from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port}"
|
63
|
+
RFlow.logger.debug { "#{self.class.name}: Received #{data.bytesize} bytes of data from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port}" }
|
69
64
|
super
|
70
65
|
end
|
71
66
|
|
72
67
|
|
73
68
|
def process_http_request
|
74
|
-
RFlow.logger.debug "Received
|
69
|
+
RFlow.logger.debug { "#{self.class.name}: Received HTTP request from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port} for #{@http_request_uri}" }
|
75
70
|
|
76
71
|
processing_event = RFlow::Message::ProcessingEvent.new(server.instance_uuid, Time.now.utc)
|
77
72
|
|
@@ -94,7 +89,7 @@ class RFlow
|
|
94
89
|
request_message.data.headers[name] = val
|
95
90
|
end
|
96
91
|
|
97
|
-
processing_event.context = signature
|
92
|
+
processing_event.context = signature.to_s
|
98
93
|
processing_event.completed_at = Time.now.utc
|
99
94
|
request_message.provenance << processing_event
|
100
95
|
|
@@ -103,7 +98,6 @@ class RFlow
|
|
103
98
|
|
104
99
|
|
105
100
|
def send_http_response(response_message=nil)
|
106
|
-
RFlow.logger.debug "Sending an HTTP response to #{client_ip}:#{client_port}"
|
107
101
|
resp = EventMachine::DelegatedHttpResponse.new(self)
|
108
102
|
|
109
103
|
# Default values
|
@@ -116,10 +110,12 @@ class RFlow
|
|
116
110
|
resp.status = response_message.data.status_code
|
117
111
|
resp.content = response_message.data.content
|
118
112
|
response_message.data.headers.each do |header, value|
|
119
|
-
resp[
|
113
|
+
resp.headers[header] = value
|
120
114
|
end
|
121
115
|
end
|
122
116
|
|
117
|
+
RFlow.logger.debug { "#{self.class.name}: Sending a HTTP response #{resp.status} to #{client_ip}:#{client_port}" }
|
118
|
+
|
123
119
|
resp.send_response
|
124
120
|
close_connection_after_writing
|
125
121
|
end
|
@@ -128,8 +124,8 @@ class RFlow
|
|
128
124
|
# Called when a connection is torn down for whatever reason.
|
129
125
|
# Remove this connection from the server's list
|
130
126
|
def unbind(reason=nil)
|
131
|
-
RFlow.logger.debug "Disconnected from HTTP client #{client_ip}:#{client_port} due to '#{reason}'"
|
132
|
-
server.connections.delete(self.signature)
|
127
|
+
RFlow.logger.debug { "#{self.class.name}: Disconnected from HTTP client #{client_ip}:#{client_port}#{reason.nil? ? '' : " due to '#{reason}'"}" }
|
128
|
+
server.connections.delete(self.signature.to_s)
|
133
129
|
end
|
134
130
|
end
|
135
131
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RFlow::Components::HTTP::Server do
|
4
|
+
|
5
|
+
it "should do stuff" do
|
6
|
+
c = RFlow::Components::HTTP::Server::Connection.new('a')
|
7
|
+
m = RFlow::Message.new("RFlow::Message::Data::HTTP::Response")
|
8
|
+
m.data.headers['Boom'] = 'Town'
|
9
|
+
c.send_http_response(m)
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rflow-components-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- schema/http_request.avsc
|
97
97
|
- schema/http_response.avsc
|
98
98
|
- spec/extensions_spec.rb
|
99
|
+
- spec/http_server_spec.rb
|
99
100
|
- spec/schema_spec.rb
|
100
101
|
- spec/spec_helper.rb
|
101
102
|
homepage: ''
|
@@ -124,5 +125,6 @@ specification_version: 3
|
|
124
125
|
summary: HTTP client and server components for the RFlow FBP framework
|
125
126
|
test_files:
|
126
127
|
- spec/extensions_spec.rb
|
128
|
+
- spec/http_server_spec.rb
|
127
129
|
- spec/schema_spec.rb
|
128
130
|
- spec/spec_helper.rb
|