rflow-components-http 1.0.0a2 → 1.0.0a3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c8e0aafd255f7936e411610a811d1af425de6a5
4
+ data.tar.gz: 733e7ea0910aca051f9979f0a58a2982ab645cc6
5
+ SHA512:
6
+ metadata.gz: ecde2cf8d154c68120901bebb4f7abaf80af439384e7ae314a994761b8f58b222e0d0862aea45ed2ba0f211e82fa144f3e6bcaf4b7fc36e20110bef838aa3469
7
+ data.tar.gz: dc580c77986021c51228604bea59a575cf91e84aaeaffcdf2a14e446c93bb3574df1bcd5a27637f12733f1752b06d66f98cd778081fbb7029b4e2aaf873df6e2
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color -fd
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rflow-dev
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.1
@@ -1,10 +1,7 @@
1
1
  class RFlow
2
2
  module Components
3
3
  module HTTP
4
-
5
- # The set of extensions to add capability to HTTP data types
6
4
  module Extensions
7
-
8
5
  module IPConnectionExtension
9
6
  # Default accessors
10
7
  # TODO: validate the stuffs
@@ -21,7 +18,7 @@ class RFlow
21
18
  # Need to be careful when extending to not clobber data already in data_object
22
19
  module HTTPRequestExtension
23
20
  def self.extended(base_data)
24
- base_data.data_object ||= {'uri' => '/', 'method' => 'GET', 'protocol' => 'HTTP/1.0', 'headers'=>{}, 'content' => ''}
21
+ base_data.data_object ||= {'uri' => '/', 'method' => 'GET', 'protocol' => 'HTTP/1.0', 'headers' => {}, 'content' => ''}
25
22
  end
26
23
 
27
24
  # Default accessors
@@ -59,9 +56,7 @@ class RFlow
59
56
  data_object[name] = args.first.to_i
60
57
  end
61
58
  end
62
-
63
59
  end
64
-
65
60
  end
66
61
  end
67
62
  end
@@ -1,12 +1,10 @@
1
1
  require 'eventmachine'
2
2
  require 'evma_httpserver'
3
-
4
3
  require 'rflow'
5
4
 
6
5
  class RFlow
7
6
  module Components
8
7
  module HTTP
9
-
10
8
  class Server < RFlow::Component
11
9
  input_port :response_port
12
10
  output_port :request_port
@@ -16,7 +14,7 @@ class RFlow
16
14
  def configure!(config)
17
15
  @listen = config['listen'] ? config['listen'] : '127.0.0.1'
18
16
  @port = config['port'] ? config['port'].to_i : 8000
19
- @connections = Hash.new
17
+ @connections = {}
20
18
  end
21
19
 
22
20
  def run!
@@ -58,59 +56,55 @@ class RFlow
58
56
  no_environment_strings
59
57
  end
60
58
 
61
-
62
59
  def receive_data(data)
63
60
  RFlow.logger.debug { "#{self.class.name}: Received #{data.bytesize} bytes of data from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port}" }
64
61
  super
65
62
  end
66
63
 
67
-
68
64
  def process_http_request
69
65
  RFlow.logger.debug { "#{self.class.name}: Received HTTP request from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port} for #{@http_request_uri}" }
70
66
 
71
- processing_event = RFlow::Message::ProcessingEvent.new(server.uuid, Time.now.utc)
72
-
73
- request_message = RFlow::Message.new('RFlow::Message::Data::HTTP::Request')
74
-
75
- request_message.data.client_ip = @client_ip
76
- request_message.data.client_port = @client_port
77
- request_message.data.server_ip = @server_ip
78
- request_message.data.server_port = @server_port
79
-
80
- request_message.data.method = @http_request_method
81
- request_message.data.uri = @http_request_uri
82
- request_message.data.query_string = @http_query_string
83
- request_message.data.protocol = @http_protocol
84
- request_message.data.content = @http_post_content
85
- request_message.data.headers = {}
86
-
87
- @http_headers.split(/\0/).each do |header|
88
- name, val = header.split(/:\s*/, 2)
89
- request_message.data.headers[name] = val
90
- end
91
-
92
- processing_event.context = signature.to_s
93
- processing_event.completed_at = Time.now.utc
94
- request_message.provenance << processing_event
67
+ server.request_port.send_message(RFlow::Message.new('RFlow::Message::Data::HTTP::Request').tap do |m|
68
+ m.data.client_ip = @client_ip
69
+ m.data.client_port = @client_port
70
+ m.data.server_ip = @server_ip
71
+ m.data.server_port = @server_port
72
+
73
+ m.data.method = @http_request_method
74
+ m.data.uri = @http_request_uri
75
+ m.data.query_string = @http_query_string
76
+ m.data.protocol = @http_protocol
77
+ m.data.content = @http_post_content
78
+ m.data.headers = {}
79
+
80
+ @http_headers.split(/\0/).each do |header|
81
+ name, val = header.split(/:\s*/, 2)
82
+ m.data.headers[name] = val
83
+ end
95
84
 
96
- server.request_port.send_message request_message
85
+ m.provenance << RFlow::Message::ProcessingEvent.new(server.uuid, Time.now.utc).tap do |e|
86
+ e.context = signature.to_s
87
+ e.completed_at = Time.now.utc
88
+ end
89
+ end)
90
+ rescue Exception => e
91
+ RFlow.logger.error "Error processing HTTP request from #{client_ip}:#{client_port} to #{@server_ip}:#{@server_port} for #{@http_request_uri}: #{e.class.name}: #{e.message}, because: #{e.backtrace.inspect}"
97
92
  end
98
93
 
99
-
100
- def send_http_response(response_message=nil)
101
- resp = EventMachine::DelegatedHttpResponse.new(self)
102
-
103
- # Default values
104
- resp.status = 200
105
- resp.content = ""
106
- resp.headers["Content-Type"] = "text/html"
107
- resp.headers["Server"] = "Apache"
108
-
109
- if response_message
110
- resp.status = response_message.data.status_code
111
- resp.content = response_message.data.content
112
- response_message.data.headers.each do |header, value|
113
- resp.headers[header] = value
94
+ def send_http_response(response_message = nil)
95
+ resp = EventMachine::DelegatedHttpResponse.new(self).tap do |r|
96
+ # Default values
97
+ r.status = 200
98
+ r.content = ""
99
+ r.headers["Content-Type"] = "text/html"
100
+ r.headers["Server"] = "Apache"
101
+
102
+ if response_message
103
+ r.status = response_message.data.status_code
104
+ r.content = response_message.data.content
105
+ response_message.data.headers.each do |header, value|
106
+ r.headers[header] = value
107
+ end
114
108
  end
115
109
  end
116
110
 
@@ -120,17 +114,15 @@ class RFlow
120
114
  close_connection_after_writing
121
115
  end
122
116
 
123
-
124
117
  # Called when a connection is torn down for whatever reason.
125
118
  # Remove this connection from the server's list
126
- def unbind(reason=nil)
119
+ def unbind(reason = nil)
127
120
  RFlow.logger.debug { "#{self.class.name}: Disconnected from HTTP client #{client_ip}:#{client_port}#{reason.nil? ? '' : " due to '#{reason}'"}" }
128
121
  server.connections.delete(self.signature.to_s)
129
122
  super()
130
123
  end
131
124
  end
132
125
  end
133
-
134
126
  end
135
127
  end
136
128
  end
@@ -1,7 +1,7 @@
1
1
  class RFlow
2
2
  module Components
3
3
  module HTTP
4
- VERSION = "1.0.0a2"
4
+ VERSION = "1.0.0a3"
5
5
  end
6
6
  end
7
7
  end
@@ -21,9 +21,10 @@ Gem::Specification.new do |s|
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_dependency 'rflow', '~> 1.0.0a1'
25
- s.add_dependency 'eventmachine_httpserver', '~> 0.2'
24
+ s.add_dependency 'rflow', '~> 1.0.0a2'
25
+ s.add_dependency 'eventmachine_httpserver_update', '~> 0.2.1'
26
26
 
27
- s.add_development_dependency 'rspec', '~> 2.6'
27
+ s.add_development_dependency 'rspec', '~> 2.99'
28
+ s.add_development_dependency 'rspec-collection_matchers', '~> 0.0.4'
28
29
  s.add_development_dependency 'rake', '~> 0.8'
29
30
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ class RFlow
4
+ module Components
5
+ module HTTP
6
+ module Extensions
7
+ describe HTTPRequestExtension do
8
+ it "should work" do
9
+ Configuration.available_data_extensions['RFlow::Message::Data::HTTP::Request'].should include(described_class)
10
+
11
+ Message.new('RFlow::Message::Data::HTTP::Request').data.tap do |d|
12
+ d.uri.should == '/'
13
+ d.method.should == 'GET'
14
+ d.query_string.should == nil
15
+ d.protocol.should == 'HTTP/1.0'
16
+ d.headers.should == {}
17
+ d.uri = '/foo'
18
+ d.uri.should == '/foo'
19
+ end
20
+ end
21
+ end
22
+
23
+ describe HTTPResponseExtension do
24
+ it "should work" do
25
+ Configuration.available_data_extensions['RFlow::Message::Data::HTTP::Response'].should include(described_class)
26
+
27
+ Message.new('RFlow::Message::Data::HTTP::Response').data.tap do |d|
28
+ d.protocol.should == 'HTTP/1.0'
29
+ d.status_code.should == 200
30
+ d.status_reason_phrase.should == 'OK'
31
+ d.headers.should == {}
32
+ d.content.should == ''
33
+ d.status_code = 404
34
+ d.status_code.should == 404
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ class RFlow
4
+ module Components
5
+ module HTTP
6
+ describe Server do
7
+ let(:conn) { Server::Connection.new('a') }
8
+
9
+ it "should return a default HTTP response" do
10
+ conn.should_receive(:send_data).with("HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Type: text/html\r\nServer: Apache\r\n\r\n")
11
+ conn.should_receive(:send_data).with('')
12
+ conn.stub(:close_connection)
13
+
14
+ conn.send_http_response(Message.new("RFlow::Message::Data::HTTP::Response"))
15
+ end
16
+
17
+ it "should use proper status reason phrases" do
18
+ conn.should_receive(:send_data).with("HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\nContent-Type: text/html\r\nServer: Apache\r\n\r\n")
19
+ conn.should_receive(:send_data).with('')
20
+ conn.stub(:close_connection)
21
+
22
+ conn.send_http_response(Message.new("RFlow::Message::Data::HTTP::Response").tap {|r| r.data.status_code = 404 })
23
+ end
24
+
25
+ it "should return a fully configured HTTP response" do
26
+ m = Message.new("RFlow::Message::Data::HTTP::Response").tap do |m|
27
+ m.data.status_code = 1337
28
+ m.data.status_reason_phrase = "JUST BECAUSE" # ignored as status phrases are overwritten
29
+ m.data.headers['Boom'] = 'Town'
30
+ m.data.content = 'boom'
31
+ end
32
+
33
+ expected_body = "boom"
34
+
35
+ conn.should_receive(:send_data).with("HTTP/1.1 1337\r\nBoom: Town\r\nContent-Length: 4\r\nContent-Type: text/html\r\nServer: Apache\r\n\r\n")
36
+ conn.should_receive(:send_data).with('boom')
37
+ conn.stub(:close_connection)
38
+
39
+ conn.send_http_response(m)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
data/spec/schema_spec.rb CHANGED
@@ -1,9 +1,7 @@
1
- require 'spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe 'RFlow::Message::Data::HTTP::Request Avro Schema' do
4
- before(:each) do
5
- @schema_string = RFlow::Configuration.available_data_types['RFlow::Message::Data::HTTP::Request']['avro']
6
- end
4
+ let(:schema) { RFlow::Configuration.available_data_types['RFlow::Message::Data::HTTP::Request']['avro'] }
7
5
 
8
6
  it "should encode and decode an object" do
9
7
  request = {
@@ -18,26 +16,23 @@ describe 'RFlow::Message::Data::HTTP::Request Avro Schema' do
18
16
  'content' => '',
19
17
  }
20
18
 
21
- expect {encode_avro(@schema_string, request)}.to_not raise_error
22
- avro_encoded_request = encode_avro(@schema_string, request)
23
-
24
- expect {decode_avro(@schema_string, avro_encoded_request)}.to_not raise_error
25
- decoded_request = decode_avro(@schema_string, avro_encoded_request)
26
-
27
- decoded_request['method'].should == request['method']
28
- decoded_request['uri'].should == request['uri']
29
- decoded_request['query_string'].should == request['query_string']
30
- decoded_request['protocol'].should == request['protocol']
31
- decoded_request['headers'].should == request['headers']
32
- decoded_request['content'].should == request['content']
19
+ expect { encode_avro(schema, request) }.to_not raise_error
20
+ encoded_request = encode_avro(schema, request)
21
+
22
+ expect { decode_avro(schema, encoded_request) }.to_not raise_error
23
+ decode_avro(schema, encoded_request).tap do |decoded|
24
+ decoded['method'].should == request['method']
25
+ decoded['uri'].should == request['uri']
26
+ decoded['query_string'].should == request['query_string']
27
+ decoded['protocol'].should == request['protocol']
28
+ decoded['headers'].should == request['headers']
29
+ decoded['content'].should == request['content']
30
+ end
33
31
  end
34
32
  end
35
33
 
36
-
37
34
  describe 'RFlow::Message::Data::HTTP::Response Avro Schema' do
38
- before(:each) do
39
- @schema_string = RFlow::Configuration.available_data_types['RFlow::Message::Data::HTTP::Response']['avro']
40
- end
35
+ let(:schema) { RFlow::Configuration.available_data_types['RFlow::Message::Data::HTTP::Response']['avro'] }
41
36
 
42
37
  it "should encode and decode an object" do
43
38
  response = {
@@ -51,17 +46,16 @@ describe 'RFlow::Message::Data::HTTP::Response Avro Schema' do
51
46
  'content' => 'CONTENT',
52
47
  }
53
48
 
54
- expect {encode_avro(@schema_string, response)}.to_not raise_error
55
- avro_encoded_response = encode_avro(@schema_string, response)
56
-
57
- expect {decode_avro(@schema_string, avro_encoded_response)}.to_not raise_error
58
- decoded_response = decode_avro(@schema_string, avro_encoded_response)
59
-
60
- decoded_response['protocol'].should == response['protocol']
61
- decoded_response['status_code'].should == response['status_code']
62
- decoded_response['status_reason_phrase'].should == response['status_reason_phrase']
63
- decoded_response['headers'].should == response['headers']
64
- decoded_response['content'].should == response['content']
49
+ expect { encode_avro(schema, response) }.to_not raise_error
50
+ encoded_response = encode_avro(schema, response)
51
+
52
+ expect { decode_avro(schema, encoded_response) }.to_not raise_error
53
+ decode_avro(schema, encoded_response).tap do |decoded|
54
+ decoded['protocol'].should == response['protocol']
55
+ decoded['status_code'].should == response['status_code']
56
+ decoded['status_reason_phrase'].should == response['status_reason_phrase']
57
+ decoded['headers'].should == response['headers']
58
+ decoded['content'].should == response['content']
59
+ end
65
60
  end
66
61
  end
67
-
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,12 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'rflow-components-http'))
2
-
3
1
  require 'logger'
2
+ require 'rflow-components-http'
4
3
 
5
4
  RFlow.logger = Logger.new STDOUT
5
+ RFlow.logger.level = 5
6
6
 
7
7
  def decode_avro(schema_string, serialized_object)
8
8
  schema = Avro::Schema.parse(schema_string)
9
- sio = StringIO.new(serialized_object)
10
- Avro::IO::DatumReader.new(schema, schema).read Avro::IO::BinaryDecoder.new(sio)
9
+ Avro::IO::DatumReader.new(schema, schema).read Avro::IO::BinaryDecoder.new(StringIO.new(serialized_object))
11
10
  end
12
11
 
13
12
  def encode_avro(schema_string, object)
metadata CHANGED
@@ -1,78 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rflow-components-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0a2
5
- prerelease: 5
4
+ version: 1.0.0a3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael L. Artz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-04-03 00:00:00.000000000 Z
11
+ date: 2014-06-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rflow
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 1.0.0a1
19
+ version: 1.0.0a2
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 1.0.0a1
26
+ version: 1.0.0a2
30
27
  - !ruby/object:Gem::Dependency
31
- name: eventmachine_httpserver
28
+ name: eventmachine_httpserver_update
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0.2'
33
+ version: 0.2.1
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0.2'
40
+ version: 0.2.1
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '2.6'
47
+ version: '2.99'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
- version: '2.6'
54
+ version: '2.99'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-collection_matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.4
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: rake
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
- - - ~>
73
+ - - "~>"
68
74
  - !ruby/object:Gem::Version
69
75
  version: '0.8'
70
76
  type: :development
71
77
  prerelease: false
72
78
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
79
  requirements:
75
- - - ~>
80
+ - - "~>"
76
81
  - !ruby/object:Gem::Version
77
82
  version: '0.8'
78
83
  description: HTTP client and server components for the RFlow FBP framework. Also
@@ -83,52 +88,54 @@ executables: []
83
88
  extensions: []
84
89
  extra_rdoc_files: []
85
90
  files:
86
- - .gitignore
87
- - .travis.yml
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".ruby-gemset"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
88
96
  - Gemfile
89
97
  - LICENSE
90
98
  - README.md
91
99
  - Rakefile
92
100
  - lib/rflow-components-http.rb
93
101
  - lib/rflow/components/http.rb
94
- - lib/rflow/components/http/client.rb
95
102
  - lib/rflow/components/http/extensions.rb
96
103
  - lib/rflow/components/http/server.rb
97
104
  - lib/rflow/components/http/version.rb
98
105
  - rflow-components-http.gemspec
99
106
  - schema/http_request.avsc
100
107
  - schema/http_response.avsc
101
- - spec/extensions_spec.rb
102
- - spec/http_server_spec.rb
108
+ - spec/rflow/components/http/extensions/extensions_spec.rb
109
+ - spec/rflow/components/http/server_spec.rb
103
110
  - spec/schema_spec.rb
104
111
  - spec/spec_helper.rb
105
112
  homepage: https://github.com/redjack/rflow-components-http
106
113
  licenses:
107
114
  - Apache-2.0
115
+ metadata: {}
108
116
  post_install_message:
109
117
  rdoc_options: []
110
118
  require_paths:
111
119
  - lib
112
120
  required_ruby_version: !ruby/object:Gem::Requirement
113
- none: false
114
121
  requirements:
115
- - - ! '>='
122
+ - - ">="
116
123
  - !ruby/object:Gem::Version
117
124
  version: '1.9'
118
125
  required_rubygems_version: !ruby/object:Gem::Requirement
119
- none: false
120
126
  requirements:
121
- - - ! '>'
127
+ - - ">"
122
128
  - !ruby/object:Gem::Version
123
129
  version: 1.3.1
124
130
  requirements: []
125
131
  rubyforge_project: rflow-components-http
126
- rubygems_version: 1.8.24
132
+ rubygems_version: 2.2.2
127
133
  signing_key:
128
- specification_version: 3
134
+ specification_version: 4
129
135
  summary: HTTP client and server components for the RFlow FBP framework
130
136
  test_files:
131
- - spec/extensions_spec.rb
132
- - spec/http_server_spec.rb
137
+ - spec/rflow/components/http/extensions/extensions_spec.rb
138
+ - spec/rflow/components/http/server_spec.rb
133
139
  - spec/schema_spec.rb
134
140
  - spec/spec_helper.rb
141
+ has_rdoc:
File without changes
@@ -1,43 +0,0 @@
1
- require 'spec_helper.rb'
2
-
3
- describe RFlow::Components::HTTP::Extensions::HTTPRequestExtension do
4
- before(:each) do
5
- @schema_string = RFlow::Configuration.available_data_types['RFlow::Message::Data::HTTP::Request']['avro']
6
- end
7
-
8
- it "should work" do
9
- RFlow::Configuration.available_data_extensions['RFlow::Message::Data::HTTP::Request'].should include(described_class)
10
-
11
- request = RFlow::Message.new('RFlow::Message::Data::HTTP::Request')
12
- request.data.uri.should == '/'
13
- request.data.method.should == 'GET'
14
- request.data.query_string.should == nil
15
- request.data.protocol.should == 'HTTP/1.0'
16
- request.data.headers.should == {}
17
-
18
- request.data.uri = 'POST'
19
- request.data.uri.should == 'POST'
20
- end
21
-
22
- end
23
-
24
- describe RFlow::Components::HTTP::Extensions::HTTPResponseExtension do
25
- before(:each) do
26
- @schema_string = RFlow::Configuration.available_data_types['RFlow::Message::Data::HTTP::Response']['avro']
27
- end
28
-
29
- it "should work" do
30
- RFlow::Configuration.available_data_extensions['RFlow::Message::Data::HTTP::Response'].should include(described_class)
31
-
32
- response = RFlow::Message.new('RFlow::Message::Data::HTTP::Response')
33
- response.data.protocol.should == 'HTTP/1.0'
34
- response.data.status_code.should == 200
35
- response.data.status_reason_phrase.should == 'OK'
36
- response.data.headers.should == {}
37
- response.data.content.should == ''
38
-
39
- response.data.status_code = 404
40
- response.data.status_code.should == 404
41
- end
42
-
43
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RFlow::Components::HTTP::Server do
4
-
5
- it "should return a default HTTP response" do
6
- c = RFlow::Components::HTTP::Server::Connection.new('a')
7
- m = RFlow::Message.new("RFlow::Message::Data::HTTP::Response")
8
-
9
- expected_header = "HTTP/1.1 200 ...\r\nContent-Type: text/html\r\nContent-length: 0\r\nServer: Apache\r\n\r\n"
10
- expected_body = ""
11
-
12
- c.should_receive(:send_data) do |header|
13
- header.should == expected_header
14
- end
15
- c.should_receive(:send_data) do |body|
16
- body.should == expected_body
17
- end
18
- c.should_receive(:close_connection).any_number_of_times
19
-
20
- c.send_http_response(m)
21
- end
22
-
23
- it "should return a fully configured HTTP response" do
24
- c = RFlow::Components::HTTP::Server::Connection.new('a')
25
-
26
- m = RFlow::Message.new("RFlow::Message::Data::HTTP::Response")
27
- m.data.status_code = 1337
28
- m.data.status_reason_phrase = "JUST BECAUSE"
29
- m.data.headers['Boom'] = 'Town'
30
- m.data.content = 'boom'
31
-
32
- expected_header = "HTTP/1.1 1337 ...\r\nBoom: Town\r\nContent-Type: text/html\r\nContent-length: 4\r\nServer: Apache\r\n\r\n"
33
- expected_body = "boom"
34
-
35
- c.should_receive(:send_data) do |header|
36
- header.should == expected_header
37
- end
38
- c.should_receive(:send_data) do |body|
39
- body.should == expected_body
40
- end
41
- c.should_receive(:close_connection).any_number_of_times
42
-
43
- c.send_http_response(m)
44
- end
45
-
46
- end