rflow-components-http 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in rflow-components-http.gemspec
4
- gem 'avro', :path => "../avro/lang/ruby"
5
- gem 'rflow', :path => "../rflow"
6
3
  gemspec
@@ -6,12 +6,12 @@ class RFlow
6
6
  module HTTP
7
7
  # Load the schemas
8
8
  SCHEMA_DIRECTORY = ::File.expand_path(::File.join(::File.dirname(__FILE__), '..', '..', '..', 'schema'))
9
-
9
+
10
10
  SCHEMA_FILES = {
11
11
  'http_response.avsc' => 'RFlow::Message::Data::HTTP::Response',
12
12
  'http_request.avsc' => 'RFlow::Message::Data::HTTP::Request',
13
13
  }
14
-
14
+
15
15
  SCHEMA_FILES.each do |file_name, data_type_name|
16
16
  schema_string = ::File.read(::File.join(SCHEMA_DIRECTORY, file_name))
17
17
  RFlow::Configuration.add_available_data_type data_type_name, 'avro', schema_string
@@ -23,7 +23,7 @@ class RFlow
23
23
  RFlow::Configuration.add_available_data_extension('RFlow::Message::Data::HTTP::Request',
24
24
  RFlow::Components::HTTP::Extensions::HTTPRequestExtension)
25
25
 
26
-
26
+
27
27
  RFlow::Configuration.add_available_data_extension('RFlow::Message::Data::HTTP::Response',
28
28
  RFlow::Components::HTTP::Extensions::IPConnectionExtension)
29
29
  RFlow::Configuration.add_available_data_extension('RFlow::Message::Data::HTTP::Response',
@@ -17,7 +17,7 @@ class RFlow
17
17
  end
18
18
  end
19
19
  end
20
-
20
+
21
21
  # Need to be careful when extending to not clobber data already in data_object
22
22
  module HTTPRequestExtension
23
23
  def self.extended(base_data)
@@ -34,7 +34,7 @@ class RFlow
34
34
  end
35
35
  end
36
36
  end
37
-
37
+
38
38
  # Need to be careful when extending to not clobber data already in data_object
39
39
  module HTTPResponseExtension
40
40
  def self.extended(base_data)
@@ -59,7 +59,7 @@ class RFlow
59
59
  data_object[name] = args.first.to_i
60
60
  end
61
61
  end
62
-
62
+
63
63
  end
64
64
 
65
65
  end
@@ -10,9 +10,9 @@ class RFlow
10
10
  class Server < RFlow::Component
11
11
  input_port :response_port
12
12
  output_port :request_port
13
-
13
+
14
14
  attr_accessor :port, :listen, :server_signature, :connections
15
-
15
+
16
16
  def configure!(config)
17
17
  @listen = config['listen'] ? config['listen'] : '127.0.0.1'
18
18
  @port = config['port'] ? config['port'].to_i : 8000
@@ -43,7 +43,7 @@ class RFlow
43
43
  end
44
44
  end
45
45
  end
46
-
46
+
47
47
  class Connection < EventMachine::Connection
48
48
  include EventMachine::HttpServer
49
49
 
@@ -58,16 +58,16 @@ class RFlow
58
58
  no_environment_strings
59
59
  end
60
60
 
61
-
61
+
62
62
  def receive_data(data)
63
63
  RFlow.logger.debug { "#{self.class.name}: Received #{data.bytesize} bytes of data from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port}" }
64
64
  super
65
65
  end
66
-
67
-
66
+
67
+
68
68
  def process_http_request
69
69
  RFlow.logger.debug { "#{self.class.name}: Received HTTP request from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port} for #{@http_request_uri}" }
70
-
70
+
71
71
  processing_event = RFlow::Message::ProcessingEvent.new(server.instance_uuid, Time.now.utc)
72
72
 
73
73
  request_message = RFlow::Message.new('RFlow::Message::Data::HTTP::Request')
@@ -83,12 +83,12 @@ class RFlow
83
83
  request_message.data.protocol = @http_protocol
84
84
  request_message.data.content = @http_post_content
85
85
  request_message.data.headers = {}
86
-
86
+
87
87
  @http_headers.split(/\0/).each do |header|
88
88
  name, val = header.split(/:\s*/, 2)
89
89
  request_message.data.headers[name] = val
90
90
  end
91
-
91
+
92
92
  processing_event.context = signature.to_s
93
93
  processing_event.completed_at = Time.now.utc
94
94
  request_message.provenance << processing_event
@@ -96,7 +96,7 @@ class RFlow
96
96
  server.request_port.send_message request_message
97
97
  end
98
98
 
99
-
99
+
100
100
  def send_http_response(response_message=nil)
101
101
  resp = EventMachine::DelegatedHttpResponse.new(self)
102
102
 
@@ -105,7 +105,7 @@ class RFlow
105
105
  resp.content = ""
106
106
  resp.headers["Content-Type"] = "text/html"
107
107
  resp.headers["Server"] = "Apache"
108
-
108
+
109
109
  if response_message
110
110
  resp.status = response_message.data.status_code
111
111
  resp.content = response_message.data.content
@@ -115,17 +115,18 @@ class RFlow
115
115
  end
116
116
 
117
117
  RFlow.logger.debug { "#{self.class.name}: Sending a HTTP response #{resp.status} to #{client_ip}:#{client_port}" }
118
-
118
+
119
119
  resp.send_response
120
120
  close_connection_after_writing
121
121
  end
122
122
 
123
-
123
+
124
124
  # Called when a connection is torn down for whatever reason.
125
125
  # Remove this connection from the server's list
126
126
  def unbind(reason=nil)
127
127
  RFlow.logger.debug { "#{self.class.name}: Disconnected from HTTP client #{client_ip}:#{client_port}#{reason.nil? ? '' : " due to '#{reason}'"}" }
128
128
  server.connections.delete(self.signature.to_s)
129
+ super()
129
130
  end
130
131
  end
131
132
  end
@@ -1,7 +1,7 @@
1
1
  class RFlow
2
2
  module Components
3
3
  module HTTP
4
- VERSION = "0.0.6"
4
+ VERSION = "0.0.7"
5
5
  end
6
6
  end
7
7
  end
@@ -6,10 +6,10 @@ Gem::Specification.new do |s|
6
6
  s.name = "rflow-components-http"
7
7
  s.version = RFlow::Components::HTTP::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.required_ruby_version = '~> 1.9'
9
+ s.required_ruby_version = '>= 1.9'
10
10
  s.authors = ["Michael L. Artz"]
11
11
  s.email = ["michael.artz@redjack.com"]
12
- s.homepage = ""
12
+ s.homepage = "https://github.com/redjack/rflow-components-http"
13
13
  s.summary = %q{HTTP client and server components for the RFlow FBP framework}
14
14
  s.description = %q{HTTP client and server components for the RFlow FBP framework. Also includes the necessary HTTP::Request and HTTP::Response message types}
15
15
 
@@ -18,7 +18,7 @@ describe RFlow::Components::HTTP::Extensions::HTTPRequestExtension do
18
18
  request.data.uri = 'POST'
19
19
  request.data.uri.should == 'POST'
20
20
  end
21
-
21
+
22
22
  end
23
23
 
24
24
  describe RFlow::Components::HTTP::Extensions::HTTPResponseExtension do
@@ -28,7 +28,7 @@ describe RFlow::Components::HTTP::Extensions::HTTPResponseExtension do
28
28
 
29
29
  it "should work" do
30
30
  RFlow::Configuration.available_data_extensions['RFlow::Message::Data::HTTP::Response'].should include(described_class)
31
-
31
+
32
32
  response = RFlow::Message.new('RFlow::Message::Data::HTTP::Response')
33
33
  response.data.protocol.should == 'HTTP/1.0'
34
34
  response.data.status_code.should == 200
@@ -39,5 +39,5 @@ describe RFlow::Components::HTTP::Extensions::HTTPResponseExtension do
39
39
  response.data.status_code = 404
40
40
  response.data.status_code.should == 404
41
41
  end
42
-
42
+
43
43
  end
data/spec/schema_spec.rb CHANGED
@@ -4,7 +4,7 @@ describe 'RFlow::Message::Data::HTTP::Request Avro Schema' do
4
4
  before(:each) do
5
5
  @schema_string = RFlow::Configuration.available_data_types['RFlow::Message::Data::HTTP::Request']['avro']
6
6
  end
7
-
7
+
8
8
  it "should encode and decode an object" do
9
9
  request = {
10
10
  'method' => 'METHOD',
@@ -38,7 +38,7 @@ describe 'RFlow::Message::Data::HTTP::Response Avro Schema' do
38
38
  before(:each) do
39
39
  @schema_string = RFlow::Configuration.available_data_types['RFlow::Message::Data::HTTP::Response']['avro']
40
40
  end
41
-
41
+
42
42
  it "should encode and decode an object" do
43
43
  response = {
44
44
  'protocol' => 'METHOD',
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rflow-c
3
3
  require 'logger'
4
4
 
5
5
  RFlow.logger = Logger.new STDOUT
6
-
6
+
7
7
  def decode_avro(schema_string, serialized_object)
8
8
  schema = Avro::Schema.parse(schema_string)
9
9
  sio = StringIO.new(serialized_object)
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.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -99,7 +99,7 @@ files:
99
99
  - spec/http_server_spec.rb
100
100
  - spec/schema_spec.rb
101
101
  - spec/spec_helper.rb
102
- homepage: ''
102
+ homepage: https://github.com/redjack/rflow-components-http
103
103
  licenses: []
104
104
  post_install_message:
105
105
  rdoc_options: []
@@ -108,7 +108,7 @@ require_paths:
108
108
  required_ruby_version: !ruby/object:Gem::Requirement
109
109
  none: false
110
110
  requirements:
111
- - - ~>
111
+ - - ! '>='
112
112
  - !ruby/object:Gem::Version
113
113
  version: '1.9'
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement