reel-rack 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c61306f5108aecfb3610f71ddc1bfc032592193b
4
- data.tar.gz: 62ffa8bc88e7128ebae5c3d4ab39b8477a0efd9e
3
+ metadata.gz: 63b096952fd168d6a393e3e72a1e042cbd46d48e
4
+ data.tar.gz: e6fb8172123d070e07cb0da3c1e48be553b9fb89
5
5
  SHA512:
6
- metadata.gz: 8ee8a4a4c93aec6375caf87e314ec73890b275274f3c92a4664f15bb672dfa78278d4ed5b27204dc60676a636b6e9521c3f150a8466ebf0dd183253f11fb28dc
7
- data.tar.gz: ba63f4cd58b68d51de6ba4ba91790945c971e445dac2f7246f5e5f0015db46f28f04f90541a8ee39274451d0bcd84c62cdd379c2b8674dd541721f13ae4aaebc
6
+ metadata.gz: 1d123755ec3fa199eafc3740be39dae4f28f16d9e9e8bf9b3b1127e4292faeef4df8b1dbe6a8bb6d807637c526169c223285d436a3ab942a24b3f2100e5aa127
7
+ data.tar.gz: 86aaab1608695ce38ab53950cf46f8a312bcc301556f65b34c680e3071c5a9edfd7169274c5bae26d6a646ed500ed5bd579bd33057d7dfdd8447b0a59e157fe4
data/.rspec CHANGED
@@ -1,4 +1,5 @@
1
- --color
2
- --format documentation
1
+ --color
2
+ --format documentation
3
3
  --backtrace
4
- --default_path spec
4
+ --order random
5
+ --warnings
@@ -1,8 +1,9 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
+ - 2.1.2
4
5
  - ruby-head
5
- - jruby-19mode
6
+ - jruby
6
7
  - jruby-head
7
8
  - rbx-2
8
9
 
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.2.1 (2014-12-17)
2
+ ------------------
3
+ * Bugfixes for responding with chunked encoding
4
+
1
5
  0.2.0 (2014-04-15)
2
6
  ------------------
3
7
  * Updated to be API compatible with Reel 0.5.0
@@ -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?(:to_str)
44
- request.respond status_symbol(status), headers, body.to_str
45
- elsif body.respond_to?(:each)
46
- request.respond status_symbol(status), headers.merge(:transfer_encoding => :chunked)
47
- body.each { |chunk| request << chunk }
48
- request.finish_response
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"
@@ -1,5 +1,5 @@
1
1
  module Reel
2
2
  module Rack
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -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, {"Content-Type" => "text/plain"}, [body]] }
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
- it "runs a basic Hello World app" do
19
+ before do
17
20
  # Hax to wait for server to be started
18
21
  subject.inspect
22
+ end
19
23
 
20
- expect(Net::HTTP.get(URI("http://#{host}:#{port}"))).to eq body
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
- uri = URI("http://#{host}:#{port}/")
30
- http = Net::HTTP.new(uri.host, uri.port)
31
- http.set_debug_output($stderr)
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
- subject.terminate
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.0
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-04-15 00:00:00.000000000 Z
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.0
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: