reel 0.4.0.pre7 → 0.4.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.
- checksums.yaml +4 -4
- data/CHANGES.md +3 -3
- data/lib/reel/connection.rb +7 -7
- data/lib/reel/request_parser.rb +19 -13
- data/lib/reel/response_writer.rb +4 -3
- data/lib/reel/ssl_server.rb +7 -5
- data/lib/reel/version.rb +1 -1
- data/reel.gemspec +3 -3
- data/spec/reel/connection_spec.rb +64 -41
- data/spec/reel/response_spec.rb +4 -2
- data/spec/reel/response_writer_spec.rb +18 -0
- data/spec/reel/websocket_spec.rb +8 -4
- data/spec/spec_helper.rb +2 -3
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea63b536704d29dc28c875c4160bc25937d989b5
|
4
|
+
data.tar.gz: e3d5d422b33b49c35932238dc00dd0847eaca7f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5d23ce9c146c86b313f5aa35f218e37e172001a7e29f8a39945a68e995ed9dcaf61bebc987558224b2c950917628a10f39b5428c50fd3451eda7e4ea15eb2f9
|
7
|
+
data.tar.gz: 73f35c9e99d133135d39ec18d77a04f2a71ce56170f23ccb36f766194a722595b31fa3856769b5c701a8e468c77293a317302711544f13aef89d9375c847e805
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
0.4.0
|
2
|
-
|
1
|
+
0.4.0
|
2
|
+
-----
|
3
3
|
* Rack adapter moved to the reel-rack project
|
4
4
|
* Pipelining support
|
5
5
|
* Reel::Connection#each_request for iterating through keep-alive requests
|
@@ -11,7 +11,7 @@
|
|
11
11
|
* Remove `on_error` callback system
|
12
12
|
* Increase buffer size
|
13
13
|
* Remove Reel::App (unmaintained, sorry)
|
14
|
-
* Reel::CODENAME added (
|
14
|
+
* Reel::CODENAME added (0.4.0 is "Garbo")
|
15
15
|
|
16
16
|
0.3.0
|
17
17
|
-----
|
data/lib/reel/connection.rb
CHANGED
@@ -18,14 +18,14 @@ module Reel
|
|
18
18
|
attr_reader :buffer_size
|
19
19
|
|
20
20
|
def initialize(socket, buffer_size = nil)
|
21
|
-
@attached
|
22
|
-
@socket
|
23
|
-
@keepalive
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
27
|
-
reset_request
|
21
|
+
@attached = true
|
22
|
+
@socket = socket
|
23
|
+
@keepalive = true
|
24
|
+
@buffer_size = buffer_size || BUFFER_SIZE
|
25
|
+
@parser = Request::Parser.new(self)
|
26
|
+
@writer = Response::Writer.new(socket)
|
28
27
|
|
28
|
+
reset_request
|
29
29
|
@response_state = :header
|
30
30
|
end
|
31
31
|
|
data/lib/reel/request_parser.rb
CHANGED
@@ -4,10 +4,11 @@ module Reel
|
|
4
4
|
include HTTPVersionsMixin
|
5
5
|
attr_reader :socket, :connection
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@parser
|
9
|
-
@
|
10
|
-
@
|
7
|
+
def initialize(connection)
|
8
|
+
@parser = Http::Parser.new(self)
|
9
|
+
@connection = connection
|
10
|
+
@socket = connection.socket
|
11
|
+
@buffer_size = connection.buffer_size
|
11
12
|
@currently_reading = @currently_responding = nil
|
12
13
|
@pending_reads = []
|
13
14
|
@pending_responses = []
|
@@ -40,21 +41,22 @@ module Reel
|
|
40
41
|
@currently_responding || @currently_reading
|
41
42
|
end
|
42
43
|
|
43
|
-
def readpartial(size = @
|
44
|
+
def readpartial(size = @buffer_size)
|
44
45
|
bytes = @socket.readpartial(size)
|
45
46
|
@parser << bytes
|
46
47
|
end
|
47
48
|
|
48
49
|
#
|
49
|
-
#
|
50
|
+
# HTTP::Parser callbacks
|
50
51
|
#
|
51
52
|
def on_headers_complete(headers)
|
52
53
|
info = RequestInfo.new(http_method, url, http_version, headers)
|
53
|
-
req
|
54
|
-
|
55
|
-
|
56
|
-
else
|
54
|
+
req = Request.new(info, connection)
|
55
|
+
|
56
|
+
if @currently_reading
|
57
57
|
@pending_reads << req
|
58
|
+
else
|
59
|
+
@currently_reading = req
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
@@ -66,21 +68,25 @@ module Reel
|
|
66
68
|
# Mark current request as complete, set this as ready to respond.
|
67
69
|
def on_message_complete
|
68
70
|
@currently_reading.finish_reading! if @currently_reading.is_a?(Request)
|
69
|
-
|
70
|
-
|
71
|
-
else
|
71
|
+
|
72
|
+
if @currently_responding
|
72
73
|
@pending_responses << @currently_reading
|
74
|
+
else
|
75
|
+
@currently_responding = @currently_reading
|
73
76
|
end
|
77
|
+
|
74
78
|
@currently_reading = @pending_reads.shift
|
75
79
|
end
|
76
80
|
|
77
81
|
def reset
|
78
82
|
popped = @currently_responding
|
83
|
+
|
79
84
|
if req = @pending_responses.shift
|
80
85
|
@currently_responding = req
|
81
86
|
elsif @currently_responding
|
82
87
|
@currently_responding = nil
|
83
88
|
end
|
89
|
+
|
84
90
|
popped
|
85
91
|
end
|
86
92
|
end
|
data/lib/reel/response_writer.rb
CHANGED
@@ -3,9 +3,8 @@ module Reel
|
|
3
3
|
class Writer
|
4
4
|
CRLF = "\r\n"
|
5
5
|
|
6
|
-
def initialize(socket
|
6
|
+
def initialize(socket)
|
7
7
|
@socket = socket
|
8
|
-
@connection = connection
|
9
8
|
end
|
10
9
|
|
11
10
|
# Write body chunks directly to the connection
|
@@ -44,7 +43,9 @@ module Reel
|
|
44
43
|
# FIXME: should use Celluloid::IO.copy_stream and allow these
|
45
44
|
# calls to be multiplexed through Celluloid::IO's reactor
|
46
45
|
# Until then we need a thread for each of these responses
|
47
|
-
Celluloid.defer { IO.copy_stream(response.body, @socket) }
|
46
|
+
Celluloid.defer { IO.copy_stream(response.body, @socket.to_io) }
|
47
|
+
# @socket currently not being converted to appropriate IO object automatically.
|
48
|
+
# Convert the object in advance to still enjoy IO.copy_stream coverage.
|
48
49
|
end
|
49
50
|
ensure
|
50
51
|
response.body.close
|
data/lib/reel/ssl_server.rb
CHANGED
@@ -8,15 +8,17 @@ module Reel
|
|
8
8
|
# Ideally we can encapsulate this rather than making Ruby OpenSSL a
|
9
9
|
# mandatory part of the Reel API. It would be nice to support
|
10
10
|
# alternatives (e.g. Puma's MiniSSL)
|
11
|
-
ssl_context
|
11
|
+
ssl_context = OpenSSL::SSL::SSLContext.new
|
12
12
|
ssl_context.cert = OpenSSL::X509::Certificate.new options.fetch(:cert)
|
13
13
|
ssl_context.key = OpenSSL::PKey::RSA.new options.fetch(:key)
|
14
14
|
|
15
|
-
#
|
15
|
+
# We don't presently support verifying client certificates
|
16
|
+
# TODO: support client certificates!
|
16
17
|
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
17
18
|
|
18
19
|
@tcpserver = Celluloid::IO::TCPServer.new(host, port)
|
19
|
-
@server
|
20
|
+
@server = Celluloid::IO::SSLServer.new(@tcpserver, ssl_context)
|
21
|
+
|
20
22
|
@server.listen(backlog)
|
21
23
|
@callback = callback
|
22
24
|
|
@@ -27,8 +29,8 @@ module Reel
|
|
27
29
|
loop do
|
28
30
|
begin
|
29
31
|
socket = @server.accept
|
30
|
-
rescue OpenSSL::SSL::SSLError
|
31
|
-
|
32
|
+
rescue OpenSSL::SSL::SSLError => ex
|
33
|
+
Logger.warn "Error accepting SSLSocket: #{ex.class}: #{ex.to_s}"
|
32
34
|
retry
|
33
35
|
end
|
34
36
|
|
data/lib/reel/version.rb
CHANGED
data/reel.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
|
|
5
5
|
gem.authors = ["Tony Arcieri"]
|
6
6
|
gem.email = ["tony.arcieri@gmail.com"]
|
7
7
|
gem.description = "A Celluloid::IO-powered HTTP server"
|
8
|
-
gem.summary = "A
|
8
|
+
gem.summary = "A Reel good HTTP server"
|
9
9
|
gem.homepage = "https://github.com/celluloid/reel"
|
10
10
|
|
11
11
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -15,9 +15,9 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Reel::VERSION
|
17
17
|
|
18
|
-
gem.add_runtime_dependency 'celluloid', '>= 0.15.
|
18
|
+
gem.add_runtime_dependency 'celluloid', '>= 0.15.1'
|
19
19
|
gem.add_runtime_dependency 'celluloid-io', '>= 0.15.0'
|
20
|
-
gem.add_runtime_dependency 'http', '>= 0.5.0
|
20
|
+
gem.add_runtime_dependency 'http', '>= 0.5.0'
|
21
21
|
gem.add_runtime_dependency 'http_parser.rb', '>= 0.6.0.beta.2'
|
22
22
|
gem.add_runtime_dependency 'websocket_parser', '>= 0.1.4'
|
23
23
|
|
@@ -4,7 +4,8 @@ describe Reel::Connection do
|
|
4
4
|
let(:fixture_path) { File.expand_path("../../fixtures/example.txt", __FILE__) }
|
5
5
|
|
6
6
|
it "reads requests without bodies" do
|
7
|
-
with_socket_pair do |client,
|
7
|
+
with_socket_pair do |client, peer|
|
8
|
+
connection = Reel::Connection.new(peer)
|
8
9
|
client << ExampleRequest.new.to_s
|
9
10
|
request = connection.request
|
10
11
|
|
@@ -22,7 +23,8 @@ describe Reel::Connection do
|
|
22
23
|
end
|
23
24
|
|
24
25
|
it "reads requests with bodies" do
|
25
|
-
with_socket_pair do |client,
|
26
|
+
with_socket_pair do |client, peer|
|
27
|
+
connection = Reel::Connection.new(peer)
|
26
28
|
body = "Hello, world!"
|
27
29
|
example_request = ExampleRequest.new
|
28
30
|
example_request.body = body
|
@@ -38,7 +40,8 @@ describe Reel::Connection do
|
|
38
40
|
end
|
39
41
|
|
40
42
|
it "reads requests with large bodies" do
|
41
|
-
with_socket_pair do |client,
|
43
|
+
with_socket_pair do |client, peer|
|
44
|
+
connection = Reel::Connection.new(peer)
|
42
45
|
client << ExampleRequest.new.to_s
|
43
46
|
request = connection.request
|
44
47
|
|
@@ -54,7 +57,8 @@ describe Reel::Connection do
|
|
54
57
|
end
|
55
58
|
|
56
59
|
it "enumerates requests with #each_request" do
|
57
|
-
with_socket_pair do |client,
|
60
|
+
with_socket_pair do |client, peer|
|
61
|
+
connection = Reel::Connection.new(peer)
|
58
62
|
client << ExampleRequest.new.to_s
|
59
63
|
|
60
64
|
request_count = 0
|
@@ -70,7 +74,8 @@ describe Reel::Connection do
|
|
70
74
|
end
|
71
75
|
|
72
76
|
it "streams responses when transfer-encoding is chunked" do
|
73
|
-
with_socket_pair do |client,
|
77
|
+
with_socket_pair do |client, peer|
|
78
|
+
connection = Reel::Connection.new(peer)
|
74
79
|
client << ExampleRequest.new.to_s
|
75
80
|
request = connection.request
|
76
81
|
|
@@ -99,7 +104,8 @@ describe Reel::Connection do
|
|
99
104
|
end
|
100
105
|
|
101
106
|
it "reset the request after a response is sent" do
|
102
|
-
with_socket_pair do |client,
|
107
|
+
with_socket_pair do |client, peer|
|
108
|
+
connection = Reel::Connection.new(peer)
|
103
109
|
example_request = ExampleRequest.new(:get, "/", "1.1", {'Connection' => 'close'})
|
104
110
|
client << example_request
|
105
111
|
|
@@ -112,24 +118,24 @@ describe Reel::Connection do
|
|
112
118
|
end
|
113
119
|
|
114
120
|
it "raises an error trying to read two pipelines without responding first" do
|
115
|
-
with_socket_pair do |client,
|
121
|
+
with_socket_pair do |client, peer|
|
122
|
+
connection = Reel::Connection.new(peer)
|
123
|
+
|
116
124
|
2.times do
|
117
125
|
client << ExampleRequest.new.to_s
|
118
126
|
end
|
119
127
|
|
120
|
-
|
121
|
-
2.times
|
122
|
-
|
123
|
-
end
|
124
|
-
}.should raise_error(Reel::Connection::StateError)
|
128
|
+
expect do
|
129
|
+
2.times { request = connection.request }
|
130
|
+
end.to raise_error(Reel::Connection::StateError)
|
125
131
|
end
|
126
132
|
end
|
127
133
|
|
128
134
|
it "reads pipelined requests without bodies" do
|
129
|
-
with_socket_pair do |client,
|
130
|
-
|
131
|
-
|
132
|
-
|
135
|
+
with_socket_pair do |client, peer|
|
136
|
+
connection = Reel::Connection.new(peer)
|
137
|
+
|
138
|
+
3.times { client << ExampleRequest.new.to_s }
|
133
139
|
|
134
140
|
3.times do
|
135
141
|
request = connection.request
|
@@ -150,7 +156,9 @@ describe Reel::Connection do
|
|
150
156
|
end
|
151
157
|
|
152
158
|
it "reads pipelined requests with bodies" do
|
153
|
-
with_socket_pair do |client,
|
159
|
+
with_socket_pair do |client, peer|
|
160
|
+
connection = Reel::Connection.new(peer)
|
161
|
+
|
154
162
|
3.times do |i|
|
155
163
|
body = "Hello, world number #{i}!"
|
156
164
|
example_request = ExampleRequest.new
|
@@ -174,7 +182,9 @@ describe Reel::Connection do
|
|
174
182
|
end
|
175
183
|
|
176
184
|
it "reads pipelined requests with streamed bodies" do
|
177
|
-
with_socket_pair
|
185
|
+
with_socket_pair do |client, peer|
|
186
|
+
connection = Reel::Connection.new(peer, 4)
|
187
|
+
|
178
188
|
3.times do |i|
|
179
189
|
body = "Hello, world number #{i}!"
|
180
190
|
example_request = ExampleRequest.new
|
@@ -206,8 +216,10 @@ describe Reel::Connection do
|
|
206
216
|
# This test will deadlock rspec waiting unless
|
207
217
|
# connection.request works properly
|
208
218
|
it "does not block waiting for body to read before handling request" do
|
209
|
-
with_socket_pair do |client,
|
219
|
+
with_socket_pair do |client, peer|
|
220
|
+
connection = Reel::Connection.new(peer)
|
210
221
|
example_request = ExampleRequest.new
|
222
|
+
|
211
223
|
content = "Hi guys! Sorry I'm late to the party."
|
212
224
|
example_request['Content-Length'] = content.length
|
213
225
|
client << example_request.to_s
|
@@ -220,8 +232,10 @@ describe Reel::Connection do
|
|
220
232
|
end
|
221
233
|
|
222
234
|
it "blocks on read until written" do
|
223
|
-
with_socket_pair do |client,
|
235
|
+
with_socket_pair do |client, peer|
|
236
|
+
connection = Reel::Connection.new(peer)
|
224
237
|
example_request = ExampleRequest.new
|
238
|
+
|
225
239
|
content = "Hi guys! Sorry I'm late to the party."
|
226
240
|
example_request['Content-Length'] = content.length
|
227
241
|
client << example_request.to_s
|
@@ -244,8 +258,10 @@ describe Reel::Connection do
|
|
244
258
|
end
|
245
259
|
|
246
260
|
it "streams body properly with #read and buffered body" do
|
247
|
-
with_socket_pair do |client,
|
261
|
+
with_socket_pair do |client, peer|
|
262
|
+
connection = Reel::Connection.new(peer)
|
248
263
|
example_request = ExampleRequest.new
|
264
|
+
|
249
265
|
content = "I'm data you can stream!"
|
250
266
|
example_request['Content-Length'] = content.length
|
251
267
|
client << example_request.to_s
|
@@ -266,8 +282,10 @@ describe Reel::Connection do
|
|
266
282
|
|
267
283
|
context "#readpartial" do
|
268
284
|
it "streams request bodies" do
|
269
|
-
with_socket_pair
|
285
|
+
with_socket_pair do |client, peer|
|
286
|
+
connection = Reel::Connection.new(peer, 8)
|
270
287
|
example_request = ExampleRequest.new
|
288
|
+
|
271
289
|
content = "I'm data you can stream!"
|
272
290
|
example_request['Content-Length'] = content.length
|
273
291
|
client << example_request.to_s
|
@@ -288,8 +306,10 @@ describe Reel::Connection do
|
|
288
306
|
|
289
307
|
context "#each" do
|
290
308
|
it "streams request bodies" do
|
291
|
-
with_socket_pair
|
309
|
+
with_socket_pair do |client, peer|
|
310
|
+
connection = Reel::Connection.new(peer)
|
292
311
|
example_request = ExampleRequest.new
|
312
|
+
|
293
313
|
content = "I'm data you can stream!"
|
294
314
|
example_request['Content-Length'] = content.length
|
295
315
|
client << example_request.to_s
|
@@ -309,7 +329,8 @@ describe Reel::Connection do
|
|
309
329
|
|
310
330
|
describe "IO#read duck typing" do
|
311
331
|
it "raises an exception if length is a negative value" do
|
312
|
-
with_socket_pair do |client,
|
332
|
+
with_socket_pair do |client, peer|
|
333
|
+
connection = Reel::Connection.new(peer)
|
313
334
|
example_request = ExampleRequest.new
|
314
335
|
|
315
336
|
client << example_request.to_s
|
@@ -320,7 +341,8 @@ describe Reel::Connection do
|
|
320
341
|
end
|
321
342
|
|
322
343
|
it "returns an empty string if the length is zero" do
|
323
|
-
with_socket_pair do |client,
|
344
|
+
with_socket_pair do |client, peer|
|
345
|
+
connection = Reel::Connection.new(peer)
|
324
346
|
example_request = ExampleRequest.new
|
325
347
|
|
326
348
|
client << example_request.to_s
|
@@ -331,10 +353,10 @@ describe Reel::Connection do
|
|
331
353
|
end
|
332
354
|
|
333
355
|
it "reads to EOF if length is nil, even small buffer" do
|
334
|
-
with_socket_pair
|
335
|
-
|
356
|
+
with_socket_pair do |client, peer|
|
357
|
+
connection = Reel::Connection.new(peer, 4)
|
336
358
|
example_request = ExampleRequest.new
|
337
|
-
example_request.body =
|
359
|
+
example_request.body = "Hello, world!"
|
338
360
|
connection.buffer_size.should == 4
|
339
361
|
|
340
362
|
client << example_request.to_s
|
@@ -345,10 +367,11 @@ describe Reel::Connection do
|
|
345
367
|
end
|
346
368
|
|
347
369
|
it "reads to EOF if length is nil" do
|
348
|
-
with_socket_pair do |client,
|
349
|
-
|
370
|
+
with_socket_pair do |client, peer|
|
371
|
+
connection = Reel::Connection.new(peer)
|
350
372
|
example_request = ExampleRequest.new
|
351
|
-
example_request.body =
|
373
|
+
example_request.body = "Hello, world!"
|
374
|
+
|
352
375
|
|
353
376
|
client << example_request.to_s
|
354
377
|
request = connection.request
|
@@ -358,10 +381,10 @@ describe Reel::Connection do
|
|
358
381
|
end
|
359
382
|
|
360
383
|
it "uses the optional buffer to recieve data" do
|
361
|
-
with_socket_pair do |client,
|
362
|
-
|
384
|
+
with_socket_pair do |client, peer|
|
385
|
+
connection = Reel::Connection.new(peer)
|
363
386
|
example_request = ExampleRequest.new
|
364
|
-
example_request.body =
|
387
|
+
example_request.body = "Hello, world!"
|
365
388
|
|
366
389
|
client << example_request.to_s
|
367
390
|
request = connection.request
|
@@ -373,10 +396,10 @@ describe Reel::Connection do
|
|
373
396
|
end
|
374
397
|
|
375
398
|
it "returns with the content it could read when the length longer than EOF" do
|
376
|
-
with_socket_pair do |client,
|
377
|
-
|
399
|
+
with_socket_pair do |client, peer|
|
400
|
+
connection = Reel::Connection.new(peer)
|
378
401
|
example_request = ExampleRequest.new
|
379
|
-
example_request.body =
|
402
|
+
example_request.body = "Hello, world!"
|
380
403
|
|
381
404
|
client << example_request.to_s
|
382
405
|
request = connection.request
|
@@ -386,7 +409,8 @@ describe Reel::Connection do
|
|
386
409
|
end
|
387
410
|
|
388
411
|
it "returns nil at EOF if a length is passed" do
|
389
|
-
with_socket_pair do |client,
|
412
|
+
with_socket_pair do |client, peer|
|
413
|
+
connection = Reel::Connection.new(peer)
|
390
414
|
example_request = ExampleRequest.new
|
391
415
|
|
392
416
|
client << example_request.to_s
|
@@ -397,7 +421,8 @@ describe Reel::Connection do
|
|
397
421
|
end
|
398
422
|
|
399
423
|
it "returns an empty string at EOF if length is nil" do
|
400
|
-
with_socket_pair do |client,
|
424
|
+
with_socket_pair do |client, peer|
|
425
|
+
connection = Reel::Connection.new(peer)
|
401
426
|
example_request = ExampleRequest.new
|
402
427
|
|
403
428
|
client << example_request.to_s
|
@@ -406,7 +431,5 @@ describe Reel::Connection do
|
|
406
431
|
request.read.should be_empty
|
407
432
|
end
|
408
433
|
end
|
409
|
-
|
410
434
|
end
|
411
|
-
|
412
435
|
end
|
data/spec/reel/response_spec.rb
CHANGED
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Reel::Response do
|
4
4
|
it "streams enumerables" do
|
5
|
-
with_socket_pair do |client,
|
5
|
+
with_socket_pair do |client, peer|
|
6
|
+
connection = Reel::Connection.new(peer)
|
6
7
|
client << ExampleRequest.new.to_s
|
7
8
|
request = connection.request
|
8
9
|
|
@@ -17,7 +18,8 @@ describe Reel::Response do
|
|
17
18
|
end
|
18
19
|
|
19
20
|
it "canonicalizes response headers" do
|
20
|
-
with_socket_pair do |client,
|
21
|
+
with_socket_pair do |client, peer|
|
22
|
+
connection = Reel::Connection.new(peer)
|
21
23
|
client << ExampleRequest.new.to_s
|
22
24
|
request = connection.request
|
23
25
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Reel::Response::Writer do
|
4
|
+
let(:fixture_path) { File.expand_path("../../fixtures/example.txt", __FILE__) }
|
5
|
+
let(:expected_response) { "HTTP/1.1 200 OK\r\nContent-Length: 56\r\n\r\n#{File.read(fixture_path)}" }
|
6
|
+
it "streams static files" do
|
7
|
+
with_socket_pair do |socket, peer|
|
8
|
+
writer = described_class.new(socket)
|
9
|
+
|
10
|
+
File.open(fixture_path, 'r') do |file|
|
11
|
+
response = Reel::Response.new(:ok, {}, file)
|
12
|
+
writer.handle_response(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
peer.readpartial(4096).should eq expected_response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/reel/websocket_spec.rb
CHANGED
@@ -7,7 +7,8 @@ describe Reel::WebSocket do
|
|
7
7
|
let(:another_message) { "What's going on?" }
|
8
8
|
|
9
9
|
it "performs websocket handshakes" do
|
10
|
-
with_socket_pair do |client,
|
10
|
+
with_socket_pair do |client, peer|
|
11
|
+
connection = Reel::Connection.new(peer)
|
11
12
|
client << handshake.to_data
|
12
13
|
|
13
14
|
request = connection.request
|
@@ -21,7 +22,8 @@ describe Reel::WebSocket do
|
|
21
22
|
end
|
22
23
|
|
23
24
|
it "raises an error if trying to close a connection upgraded to socket" do
|
24
|
-
with_socket_pair do |client,
|
25
|
+
with_socket_pair do |client, peer|
|
26
|
+
connection = Reel::Connection.new(peer)
|
25
27
|
client << handshake.to_data
|
26
28
|
|
27
29
|
websocket = connection.request.websocket
|
@@ -76,7 +78,8 @@ describe Reel::WebSocket do
|
|
76
78
|
end
|
77
79
|
|
78
80
|
it "raises a RequestError when connection used after it was upgraded" do
|
79
|
-
with_socket_pair do |client,
|
81
|
+
with_socket_pair do |client, peer|
|
82
|
+
connection = Reel::Connection.new(peer)
|
80
83
|
client << handshake.to_data
|
81
84
|
|
82
85
|
remote_host = connection.remote_host
|
@@ -92,7 +95,8 @@ describe Reel::WebSocket do
|
|
92
95
|
end
|
93
96
|
|
94
97
|
def with_websocket_pair
|
95
|
-
with_socket_pair do |client,
|
98
|
+
with_socket_pair do |client, peer|
|
99
|
+
connection = Reel::Connection.new(peer)
|
96
100
|
client << handshake.to_data
|
97
101
|
request = connection.request
|
98
102
|
|
data/spec/spec_helper.rb
CHANGED
@@ -24,7 +24,7 @@ ensure
|
|
24
24
|
server.terminate if server && server.alive?
|
25
25
|
end
|
26
26
|
|
27
|
-
def with_socket_pair
|
27
|
+
def with_socket_pair
|
28
28
|
host = '127.0.0.1'
|
29
29
|
port = 10101
|
30
30
|
|
@@ -33,8 +33,7 @@ def with_socket_pair(buffer_size = nil)
|
|
33
33
|
peer = server.accept
|
34
34
|
|
35
35
|
begin
|
36
|
-
|
37
|
-
yield client, connection
|
36
|
+
yield client, peer
|
38
37
|
ensure
|
39
38
|
server.close rescue nil
|
40
39
|
client.close rescue nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.15.
|
19
|
+
version: 0.15.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.15.
|
26
|
+
version: 0.15.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: celluloid-io
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.5.0
|
47
|
+
version: 0.5.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.5.0
|
54
|
+
version: 0.5.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: http_parser.rb
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- spec/fixtures/server.key
|
160
160
|
- spec/reel/connection_spec.rb
|
161
161
|
- spec/reel/response_spec.rb
|
162
|
+
- spec/reel/response_writer_spec.rb
|
162
163
|
- spec/reel/server_spec.rb
|
163
164
|
- spec/reel/ssl_server_spec.rb
|
164
165
|
- spec/reel/websocket_spec.rb
|
@@ -178,15 +179,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
179
|
version: '0'
|
179
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
181
|
requirements:
|
181
|
-
- - '
|
182
|
+
- - '>='
|
182
183
|
- !ruby/object:Gem::Version
|
183
|
-
version:
|
184
|
+
version: '0'
|
184
185
|
requirements: []
|
185
186
|
rubyforge_project:
|
186
187
|
rubygems_version: 2.0.3
|
187
188
|
signing_key:
|
188
189
|
specification_version: 4
|
189
|
-
summary: A
|
190
|
+
summary: A Reel good HTTP server
|
190
191
|
test_files:
|
191
192
|
- spec/fixtures/client.crt
|
192
193
|
- spec/fixtures/client.key
|
@@ -195,6 +196,7 @@ test_files:
|
|
195
196
|
- spec/fixtures/server.key
|
196
197
|
- spec/reel/connection_spec.rb
|
197
198
|
- spec/reel/response_spec.rb
|
199
|
+
- spec/reel/response_writer_spec.rb
|
198
200
|
- spec/reel/server_spec.rb
|
199
201
|
- spec/reel/ssl_server_spec.rb
|
200
202
|
- spec/reel/websocket_spec.rb
|