reel-rack 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +4 -3
- data/.travis.yml +2 -1
- data/CHANGES.md +4 -0
- data/lib/reel/rack/server.rb +15 -6
- data/lib/reel/rack/version.rb +1 -1
- data/spec/reel/rack/server_spec.rb +24 -11
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63b096952fd168d6a393e3e72a1e042cbd46d48e
|
4
|
+
data.tar.gz: e6fb8172123d070e07cb0da3c1e48be553b9fb89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d123755ec3fa199eafc3740be39dae4f28f16d9e9e8bf9b3b1127e4292faeef4df8b1dbe6a8bb6d807637c526169c223285d436a3ab942a24b3f2100e5aa127
|
7
|
+
data.tar.gz: 86aaab1608695ce38ab53950cf46f8a312bcc301556f65b34c680e3071c5a9edfd7169274c5bae26d6a646ed500ed5bd579bd33057d7dfdd8447b0a59e157fe4
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
data/lib/reel/rack/server.rb
CHANGED
@@ -31,6 +31,9 @@ module Reel
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
# Compile the regex once
|
35
|
+
CONTENT_LENGTH_HEADER = %r{^content-length$}i
|
36
|
+
|
34
37
|
def route_request(request)
|
35
38
|
options = {
|
36
39
|
:method => request.method,
|
@@ -40,12 +43,18 @@ module Reel
|
|
40
43
|
|
41
44
|
status, headers, body = app.call ::Rack::MockRequest.env_for(request.url, options)
|
42
45
|
|
43
|
-
if body.respond_to?
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
if body.respond_to? :each
|
47
|
+
# If Content-Length was specified we can send the response all at once
|
48
|
+
if headers.keys.detect { |h| h =~ CONTENT_LENGTH_HEADER }
|
49
|
+
# Can't use collect here because Rack::BodyProxy/Rack::Lint isn't a real Enumerable
|
50
|
+
full_body = ''
|
51
|
+
body.each { |b| full_body << b }
|
52
|
+
request.respond status_symbol(status), headers, full_body
|
53
|
+
else
|
54
|
+
request.respond status_symbol(status), headers.merge(:transfer_encoding => :chunked)
|
55
|
+
body.each { |chunk| request << chunk }
|
56
|
+
request.finish_response
|
57
|
+
end
|
49
58
|
else
|
50
59
|
Logger.error("don't know how to render: #{body.inspect}")
|
51
60
|
request.respond :internal_server_error, "An error occurred processing your request"
|
data/lib/reel/rack/version.rb
CHANGED
@@ -6,30 +6,31 @@ require 'rack/head'
|
|
6
6
|
describe Reel::Rack::Server do
|
7
7
|
let(:host) { "127.0.0.1" }
|
8
8
|
let(:port) { 30000 }
|
9
|
+
let(:headers) { {"Content-Type" => "text/plain", "Content-Length" => body.length.to_s} }
|
9
10
|
let(:body) { "hello world" }
|
11
|
+
let(:uri) { URI("http://#{host}:#{port}/") }
|
12
|
+
let(:http) { Net::HTTP.new(uri.host, uri.port) }
|
10
13
|
|
11
14
|
subject do
|
12
|
-
app = proc { [200,
|
15
|
+
app = proc { [200, headers, [body]] }
|
13
16
|
described_class.new(Rack::Lint.new(Rack::Head.new(app)), :Host => host, :Port => port)
|
14
17
|
end
|
15
18
|
|
16
|
-
|
19
|
+
before do
|
17
20
|
# Hax to wait for server to be started
|
18
21
|
subject.inspect
|
22
|
+
end
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
after do
|
22
25
|
subject.terminate
|
23
26
|
end
|
24
27
|
|
25
|
-
it "success with basic HTTP methods" do
|
26
|
-
# Hax to wait for server to be started
|
27
|
-
subject.inspect
|
28
28
|
|
29
|
-
|
30
|
-
http
|
31
|
-
|
29
|
+
it "runs a basic Hello World app" do
|
30
|
+
expect(http.request_get(uri.path).body).to eq body
|
31
|
+
end
|
32
32
|
|
33
|
+
it "success with basic HTTP methods" do
|
33
34
|
expect(http.request_get(uri.path).body).to eq body
|
34
35
|
expect(http.request_head(uri.path).body).to eq nil
|
35
36
|
|
@@ -37,7 +38,19 @@ describe Reel::Rack::Server do
|
|
37
38
|
expect(http.send_request('PUT', uri.path, "test").body).to eq body
|
38
39
|
expect(http.send_request('PATCH', uri.path, "test").body).to eq body
|
39
40
|
expect(http.send_request('DELETE', uri.path).body).to eq body
|
41
|
+
end
|
40
42
|
|
41
|
-
|
43
|
+
it "disables chunked transfer if a Content-Length header is set" do
|
44
|
+
expect(http.send_request('GET', uri.path, 'test')['content-length']).to_not eq nil
|
45
|
+
expect(http.send_request('GET', uri.path, 'test')['transfer-encoding']).to_not eq 'chunked'
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with no Content-Length header and the body is Enumerable" do
|
49
|
+
let(:headers) { {"Content-Type" => "text/plain"} }
|
50
|
+
|
51
|
+
it "sends a chunked transfer response if there is no Content-Length header and the body is Enumerable" do
|
52
|
+
expect(http.send_request('GET', uri.path, 'test')['content-length']).to eq nil
|
53
|
+
expect(http.send_request('GET', uri.path, 'test')['transfer-encoding']).to eq 'chunked'
|
54
|
+
end
|
42
55
|
end
|
43
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reel-rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: reel
|
@@ -129,11 +129,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.2.
|
132
|
+
rubygems_version: 2.2.2
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: Rack adapter for Reel, a Celluloid::IO web server
|
136
136
|
test_files:
|
137
137
|
- spec/reel/rack/server_spec.rb
|
138
138
|
- spec/spec_helper.rb
|
139
|
-
has_rdoc:
|