reel 0.2.0.pre → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of reel might be problematic. Click here for more details.

data/CHANGES.md CHANGED
@@ -2,6 +2,7 @@ HEAD
2
2
  ----
3
3
  * Initial WebSockets support via Reel::WebSocket
4
4
  * Experimental Rack adapter by Alberto Fernández-Capel
5
+ * Octarine (Sinatra-like DSL) support by Grant Rodgers
5
6
 
6
7
  0.1.0
7
8
  -----
data/README.md CHANGED
@@ -64,6 +64,7 @@ require 'reel'
64
64
 
65
65
  Reel::Server.supervise("0.0.0.0", 3000) do |connection|
66
66
  while request = connection.request
67
+ case request
67
68
  when Reel::Request
68
69
  puts "Client requested: #{request.method} #{request.url}"
69
70
  connection.respond :ok, "hello, world"
@@ -0,0 +1,33 @@
1
+ require 'reel'
2
+ require 'octarine'
3
+
4
+ module Reel
5
+ # Define Reel endpoints using a sinatra-like dsl (provided by octarine)
6
+ module App
7
+ def self.included(base)
8
+ base.class_eval do
9
+ include Octarine::App
10
+
11
+ attr_accessor :server
12
+ end
13
+ end
14
+
15
+ def initialize(host, port)
16
+ super()
17
+ @server = Reel::Server.supervise(host, port) do |connection|
18
+ while request = connection.request
19
+ status, headers, body = call Rack::MockRequest.env_for(request.url, :method => request.method, :input => request.body)
20
+ connection.respond status_symbol(status), headers, body.to_s
21
+ end
22
+ end
23
+ end
24
+
25
+ def status_symbol(status)
26
+ status.is_a?(Fixnum) ? Http::Response::STATUS_CODES[status].downcase.gsub(/\s|-/, '_').to_sym : status.to_sym
27
+ end
28
+
29
+ def terminate
30
+ @server.terminate
31
+ end
32
+ end
33
+ end
@@ -31,6 +31,18 @@ module Reel
31
31
  self
32
32
  end
33
33
 
34
+ # Obtain the IP address of the remote connection
35
+ def remote_ip
36
+ @socket.peeraddr(false)[3]
37
+ end
38
+ alias_method :remote_addr, :remote_ip
39
+
40
+ # Obtain the hostname of the remote connection
41
+ def remote_host
42
+ # NOTE: Celluloid::IO does not yet support non-blocking reverse DNS
43
+ @socket.peeraddr(true)[2]
44
+ end
45
+
34
46
  # Reset the current request state
35
47
  def reset_request(state = :header)
36
48
  @request_state = state
@@ -38,14 +50,6 @@ module Reel
38
50
  @parser.reset
39
51
  end
40
52
 
41
- def peer_address
42
- @socket.peeraddr(false)
43
- end
44
-
45
- def local_address
46
- @socket.addr(false)
47
- end
48
-
49
53
  # Read a request object from the connection
50
54
  def request
51
55
  return if @request_state == :websocket
@@ -139,6 +143,7 @@ module Reel
139
143
  chunk_header = chunk.bytesize.to_s(16) + Response::CRLF
140
144
  @socket << chunk_header
141
145
  @socket << chunk
146
+ @socket << Response::CRLF
142
147
  end
143
148
  alias_method :<<, :write
144
149
 
@@ -47,10 +47,8 @@ module Reel
47
47
  env["SERVER_NAME"] = @handler[:host]
48
48
  env["SERVER_PORT"] = @handler[:port]
49
49
 
50
- peer_address = connection.peer_address
51
-
52
- env["REMOTE_ADDR"] = peer_address[3]
53
- env["REMOTE_HOST"] = peer_address[2]
50
+ env["REMOTE_ADDR"] = connection.remote_ip
51
+ env["REMOTE_HOST"] = connection.remote_host
54
52
 
55
53
  env["PATH_INFO"] = request.path
56
54
  env["REQUEST_METHOD"] = request.method.to_s.upcase
@@ -1,3 +1,3 @@
1
1
  module Reel
2
- VERSION = "0.2.0.pre"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
23
23
 
24
24
  gem.add_development_dependency 'rake'
25
25
  gem.add_development_dependency 'rspec'
26
+ gem.add_development_dependency 'octarine'
26
27
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'reel/app'
3
+
4
+ describe Reel::App do
5
+ let(:app) {
6
+ Class.new do
7
+ include Reel::App
8
+
9
+ get example_path do
10
+ [200, {}, "hello foo"]
11
+ end
12
+
13
+ end
14
+ }
15
+
16
+ before(:each) do
17
+ @app = app.new(example_addr, example_port)
18
+ end
19
+
20
+ after(:each) do
21
+ @app.server.terminate if @app.server.alive?
22
+ end
23
+
24
+ it 'responds to get requests' do
25
+ res = Http.with_response(:object).get example_url
26
+ res.status.should == 200
27
+ res.headers.should == {"Connection" => "Keep-Alive", "Content-Length" => res.body.length.to_s}
28
+ res.body.should == "hello foo"
29
+ end
30
+
31
+ it 'terminates the server' do
32
+ @app.terminate
33
+ @app.server.should_not be_alive
34
+ end
35
+ end
@@ -77,7 +77,7 @@ describe Reel::Connection do
77
77
  end
78
78
 
79
79
  crlf = "\r\n"
80
- fixture = "5#{crlf}Hello5#{crlf}World0#{crlf*2}"
80
+ fixture = "5#{crlf}Hello#{crlf}5#{crlf}World#{crlf}0#{crlf*2}"
81
81
  response[(response.length - fixture.length)..-1].should eq fixture
82
82
  end
83
83
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Reel::RackWorker do
4
4
 
5
- let(:endpoint) { URI("http://#{example_addr}:#{example_port}#{example_url}") }
5
+ let(:endpoint) { URI(example_url) }
6
6
 
7
7
  let(:worker) do
8
8
  app = Proc.new do |env|
@@ -29,7 +29,6 @@ describe Reel::RackWorker do
29
29
  env["SERVER_NAME"].should == '0.0.0.0'
30
30
  env["SERVER_PORT"].should == 3000
31
31
  env["REMOTE_ADDR"].should == "127.0.0.1"
32
- env["REMOTE_HOST"].should == "127.0.0.1"
33
32
  env["PATH_INFO"].should == "/test"
34
33
  env["REQUEST_METHOD"].should == "GET"
35
34
  env["REQUEST_PATH"].should == "/test"
@@ -39,6 +38,8 @@ describe Reel::RackWorker do
39
38
  env["HTTP_ACCEPT_LANGUAGE"].should == "en-US,en;q=0.8"
40
39
  env["REQUEST_URI"].should == 'http://www.example.com/test'
41
40
 
41
+ %w(localhost 127.0.0.1).should include env["REMOTE_HOST"]
42
+
42
43
  env["rack.input"].should be_kind_of(StringIO)
43
44
  env["rack.input"].string.should == ''
44
45
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'net/http'
3
3
 
4
4
  describe Reel::Server do
5
- let(:endpoint) { URI("http://#{example_addr}:#{example_port}#{example_url}") }
5
+ let(:endpoint) { URI(example_url) }
6
6
  let(:response_body) { "ohai thar" }
7
7
 
8
8
  it "receives HTTP requests and sends responses" do
@@ -13,7 +13,7 @@ describe Reel::Server do
13
13
  request = connection.request
14
14
  request.method.should eq :get
15
15
  request.version.should eq "1.1"
16
- request.url.should eq example_url
16
+ request.url.should eq example_path
17
17
 
18
18
  connection.respond :ok, response_body
19
19
  rescue => ex
@@ -6,7 +6,8 @@ Celluloid.logger = Logger.new(logfile)
6
6
 
7
7
  def example_addr; '127.0.0.1'; end
8
8
  def example_port; 1234; end
9
- def example_url; "/example"; end
9
+ def example_path; "/example"; end
10
+ def example_url; "http://#{example_addr}:#{example_port}#{example_path}"; end
10
11
 
11
12
  def with_reel(handler)
12
13
  server = Reel::Server.new(example_addr, example_port, &handler)
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre
5
- prerelease: 6
4
+ version: 0.2.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tony Arcieri
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-10 00:00:00.000000000 Z
12
+ date: 2012-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid-io
16
- requirement: &70212936553620 !ruby/object:Gem::Requirement
16
+ requirement: &70335285356900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70212936553620
24
+ version_requirements: *70335285356900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: http
27
- requirement: &70212936553120 !ruby/object:Gem::Requirement
27
+ requirement: &70335285356400 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.2.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70212936553120
35
+ version_requirements: *70335285356400
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: http_parser.rb
38
- requirement: &70212936552660 !ruby/object:Gem::Requirement
38
+ requirement: &70335285355940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.5.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70212936552660
46
+ version_requirements: *70335285355940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: websocket_parser
49
- requirement: &70212936552200 !ruby/object:Gem::Requirement
49
+ requirement: &70335285355480 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.1.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70212936552200
57
+ version_requirements: *70335285355480
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack
60
- requirement: &70212936551740 !ruby/object:Gem::Requirement
60
+ requirement: &70335285355020 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.4.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70212936551740
68
+ version_requirements: *70335285355020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &70212936551360 !ruby/object:Gem::Requirement
71
+ requirement: &70335285354640 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70212936551360
79
+ version_requirements: *70335285354640
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70212936550900 !ruby/object:Gem::Requirement
82
+ requirement: &70335285370560 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,18 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70212936550900
90
+ version_requirements: *70335285370560
91
+ - !ruby/object:Gem::Dependency
92
+ name: octarine
93
+ requirement: &70335285370080 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70335285370080
91
102
  description: A Celluloid::IO-powered HTTP server
92
103
  email:
93
104
  - tony.arcieri@gmail.com
@@ -113,6 +124,7 @@ files:
113
124
  - examples/websockets.rb
114
125
  - lib/rack/handler/reel.rb
115
126
  - lib/reel.rb
127
+ - lib/reel/app.rb
116
128
  - lib/reel/connection.rb
117
129
  - lib/reel/logger.rb
118
130
  - lib/reel/rack_worker.rb
@@ -126,6 +138,7 @@ files:
126
138
  - logo.png
127
139
  - reel.gemspec
128
140
  - spec/fixtures/example.txt
141
+ - spec/reel/app_spec.rb
129
142
  - spec/reel/connection_spec.rb
130
143
  - spec/reel/rack_worker_spec.rb
131
144
  - spec/reel/response_spec.rb
@@ -148,21 +161,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
161
  required_rubygems_version: !ruby/object:Gem::Requirement
149
162
  none: false
150
163
  requirements:
151
- - - ! '>'
164
+ - - ! '>='
152
165
  - !ruby/object:Gem::Version
153
- version: 1.3.1
166
+ version: '0'
154
167
  requirements: []
155
168
  rubyforge_project:
156
- rubygems_version: 1.8.10
169
+ rubygems_version: 1.8.17
157
170
  signing_key:
158
171
  specification_version: 3
159
172
  summary: A reel good HTTP server
160
173
  test_files:
161
174
  - spec/fixtures/example.txt
175
+ - spec/reel/app_spec.rb
162
176
  - spec/reel/connection_spec.rb
163
177
  - spec/reel/rack_worker_spec.rb
164
178
  - spec/reel/response_spec.rb
165
179
  - spec/reel/server_spec.rb
166
180
  - spec/reel/websocket_spec.rb
167
181
  - spec/spec_helper.rb
168
- has_rdoc: