reel 0.0.1 → 0.0.2
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/.travis.yml +3 -0
- data/lib/reel/connection.rb +2 -1
- data/lib/reel/request.rb +1 -1
- data/lib/reel/request/parser.rb +7 -3
- data/lib/reel/response.rb +17 -5
- data/lib/reel/version.rb +1 -1
- data/spec/fixtures/example.txt +1 -0
- data/spec/reel/connection_spec.rb +19 -2
- metadata +14 -12
data/.travis.yml
CHANGED
data/lib/reel/connection.rb
CHANGED
@@ -11,6 +11,7 @@ module Reel
|
|
11
11
|
def initialize(socket)
|
12
12
|
@socket = socket
|
13
13
|
@keepalive = true
|
14
|
+
@parser = Request::Parser.new
|
14
15
|
reset
|
15
16
|
|
16
17
|
@response_state = :header
|
@@ -96,8 +97,8 @@ module Reel
|
|
96
97
|
|
97
98
|
def reset
|
98
99
|
@request_state = :header
|
99
|
-
@parser = Request::Parser.new
|
100
100
|
@request = nil
|
101
|
+
@parser.reset
|
101
102
|
end
|
102
103
|
end
|
103
104
|
end
|
data/lib/reel/request.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Reel
|
2
2
|
class Request
|
3
|
-
attr_accessor :method, :version, :url
|
3
|
+
attr_accessor :method, :version, :url, :headers
|
4
4
|
METHODS = [:get, :head, :post, :put, :delete, :trace, :options, :connect, :patch]
|
5
5
|
|
6
6
|
def initialize(method, url, version = "1.1", headers = {}, connection = nil)
|
data/lib/reel/request/parser.rb
CHANGED
@@ -6,9 +6,7 @@ module Reel
|
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@parser = Http::Parser.new(self)
|
9
|
-
|
10
|
-
@finished = false
|
11
|
-
@chunk = nil
|
9
|
+
reset
|
12
10
|
end
|
13
11
|
|
14
12
|
def add(data)
|
@@ -58,6 +56,12 @@ module Reel
|
|
58
56
|
def on_message_complete
|
59
57
|
@finished = true
|
60
58
|
end
|
59
|
+
|
60
|
+
def reset
|
61
|
+
@finished = false
|
62
|
+
@headers = nil
|
63
|
+
@chunk = nil
|
64
|
+
end
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
data/lib/reel/response.rb
CHANGED
@@ -4,7 +4,7 @@ module Reel
|
|
4
4
|
STATUS_CODES = Http::Response::STATUS_CODES
|
5
5
|
SYMBOL_TO_STATUS_CODE = Http::Response::SYMBOL_TO_STATUS_CODE
|
6
6
|
CRLF = "\r\n"
|
7
|
-
|
7
|
+
|
8
8
|
attr_reader :status # Status has a special setter to coerce symbol names
|
9
9
|
attr_accessor :reason
|
10
10
|
|
@@ -19,8 +19,11 @@ module Reel
|
|
19
19
|
@headers = body_or_headers
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
case @body
|
23
|
+
when String
|
24
|
+
@headers['Content-Length'] ||= @body.bytesize
|
25
|
+
when IO
|
26
|
+
@headers['Content-Length'] ||= @body.stat.size
|
24
27
|
end
|
25
28
|
|
26
29
|
# FIXME: real HTTP versioning
|
@@ -33,7 +36,7 @@ module Reel
|
|
33
36
|
when Integer
|
34
37
|
@status = status
|
35
38
|
@reason ||= STATUS_CODES[status]
|
36
|
-
when Symbol
|
39
|
+
when Symbol
|
37
40
|
if code = SYMBOL_TO_STATUS_CODE[status]
|
38
41
|
self.status = code
|
39
42
|
else
|
@@ -47,7 +50,16 @@ module Reel
|
|
47
50
|
# Write the response out to the wire
|
48
51
|
def render(socket)
|
49
52
|
socket << render_header
|
50
|
-
|
53
|
+
|
54
|
+
case @body
|
55
|
+
when String
|
56
|
+
socket << @body
|
57
|
+
when IO
|
58
|
+
# TODO: IO.copy_stream when it works cross-platform
|
59
|
+
while data = @body.read(4096)
|
60
|
+
socket << data
|
61
|
+
end
|
62
|
+
end
|
51
63
|
end
|
52
64
|
|
53
65
|
# Convert headers into a string
|
data/lib/reel/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
This is an example of a static file being served by Reel
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Reel::Connection do
|
4
|
+
let(:fixture_path) { File.expand_path("../../fixtures/example.txt", __FILE__) }
|
5
|
+
|
4
6
|
it "reads requests without bodies" do
|
5
7
|
with_socket_pair do |client, connection|
|
6
8
|
client << ExampleRequest.new.to_s
|
@@ -30,8 +32,23 @@ describe Reel::Connection do
|
|
30
32
|
|
31
33
|
request.url.should eq "/"
|
32
34
|
request.version.should eq "1.1"
|
33
|
-
request['Content-Length'].should
|
34
|
-
request.body.should
|
35
|
+
request['Content-Length'].should eq body.length.to_s
|
36
|
+
request.body.should eq example_request.body
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "serves static files" do
|
41
|
+
with_socket_pair do |client, connection|
|
42
|
+
client << ExampleRequest.new.to_s
|
43
|
+
request = connection.read_request
|
44
|
+
|
45
|
+
fixture_text = File.read(fixture_path)
|
46
|
+
File.open(fixture_path) do |file|
|
47
|
+
connection.respond :ok, file
|
48
|
+
end
|
49
|
+
|
50
|
+
response = client.readpartial(4096)
|
51
|
+
response[(response.length - fixture_text.length)..-1].should eq fixture_text
|
35
52
|
end
|
36
53
|
end
|
37
54
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03
|
12
|
+
date: 2012-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: celluloid-io
|
16
|
-
requirement: &
|
16
|
+
requirement: &70171644061140 !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: *
|
24
|
+
version_requirements: *70171644061140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: http
|
27
|
-
requirement: &
|
27
|
+
requirement: &70171644060640 !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: *
|
35
|
+
version_requirements: *70171644060640
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: http_parser.rb
|
38
|
-
requirement: &
|
38
|
+
requirement: &70171644060180 !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: *
|
46
|
+
version_requirements: *70171644060180
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70171644059800 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70171644059800
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70171644075700 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70171644075700
|
69
69
|
description: A Celluloid::IO-powered HTTP server
|
70
70
|
email:
|
71
71
|
- tony.arcieri@gmail.com
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/reel/version.rb
|
98
98
|
- logo.png
|
99
99
|
- reel.gemspec
|
100
|
+
- spec/fixtures/example.txt
|
100
101
|
- spec/reel/connection_spec.rb
|
101
102
|
- spec/reel/server_spec.rb
|
102
103
|
- spec/spec_helper.rb
|
@@ -126,6 +127,7 @@ signing_key:
|
|
126
127
|
specification_version: 3
|
127
128
|
summary: A reel good HTTP server
|
128
129
|
test_files:
|
130
|
+
- spec/fixtures/example.txt
|
129
131
|
- spec/reel/connection_spec.rb
|
130
132
|
- spec/reel/server_spec.rb
|
131
133
|
- spec/spec_helper.rb
|