mongrel2 0.34.1.pre.357 → 0.35.0
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.
- data.tar.gz.sig +0 -0
- data/History.rdoc +10 -4
- data/lib/mongrel2.rb +2 -2
- data/lib/mongrel2/connection.rb +1 -0
- data/lib/mongrel2/websocket.rb +35 -15
- data/spec/lib/constants.rb +1 -1
- data/spec/mongrel2/websocket_spec.rb +64 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
== v0.
|
2
|
-
|
3
|
-
-
|
4
|
-
|
1
|
+
== v0.35.0 [2012-12-11] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
- Allow WebSocket frames to be set to reserved opcodes
|
4
|
+
- Allow WebSocket opcodes to be set numerically
|
5
|
+
- Add a #socket_id method to all WebSocket frame types.
|
6
|
+
* Created a Mongrel2::WebSocket::Methods mixin with the
|
7
|
+
implementation of the method.
|
8
|
+
* Included the new mixin in WebSocket::Frame,
|
9
|
+
WebSocket::ClientHandshake, and WebSocket::ServerHandshake
|
10
|
+
- Ensure the ZMQ context is closed when #run exits.
|
5
11
|
|
6
12
|
== v0.34.0 [2012-10-17] Michael Granger <ged@FaerieMUD.org>
|
7
13
|
|
data/lib/mongrel2.rb
CHANGED
@@ -20,10 +20,10 @@ module Mongrel2
|
|
20
20
|
abort "\n\n>>> Mongrel2 requires Ruby 1.9.2 or later. <<<\n\n" if RUBY_VERSION < '1.9.2'
|
21
21
|
|
22
22
|
# Library version constant
|
23
|
-
VERSION = '0.
|
23
|
+
VERSION = '0.35.0'
|
24
24
|
|
25
25
|
# Version-control revision constant
|
26
|
-
REVISION = %q$Revision:
|
26
|
+
REVISION = %q$Revision: d19a29e2ca5f $
|
27
27
|
|
28
28
|
|
29
29
|
require 'mongrel2/constants'
|
data/lib/mongrel2/connection.rb
CHANGED
data/lib/mongrel2/websocket.rb
CHANGED
@@ -27,6 +27,11 @@ require 'mongrel2/constants'
|
|
27
27
|
# ...
|
28
28
|
# end
|
29
29
|
# end
|
30
|
+
#
|
31
|
+
# == References
|
32
|
+
#
|
33
|
+
# * http://tools.ietf.org/html/rfc6455
|
34
|
+
#
|
30
35
|
module Mongrel2::WebSocket
|
31
36
|
|
32
37
|
# WebSocket-related header and status constants
|
@@ -200,9 +205,21 @@ module Mongrel2::WebSocket
|
|
200
205
|
class HandshakeError < Mongrel2::WebSocket::Error; end
|
201
206
|
|
202
207
|
|
208
|
+
# A mixin containing methods common to WebSocket frame classes.
|
209
|
+
module Methods
|
210
|
+
|
211
|
+
### Get a string identifying the websocket the frame belongs to.
|
212
|
+
def socket_id
|
213
|
+
return [ self.sender_id, self.conn_id ].join( ':' )
|
214
|
+
end
|
215
|
+
|
216
|
+
end # module Methods
|
217
|
+
|
218
|
+
|
203
219
|
# The client (request) handshake for a WebSocket opening handshake.
|
204
220
|
class ClientHandshake < Mongrel2::HTTPRequest
|
205
|
-
include Mongrel2::WebSocket::Constants
|
221
|
+
include Mongrel2::WebSocket::Constants,
|
222
|
+
Mongrel2::WebSocket::Methods
|
206
223
|
|
207
224
|
# Set this class as the one that will handle WEBSOCKET_HANDSHAKE requests
|
208
225
|
register_request_type( self, :WEBSOCKET_HANDSHAKE )
|
@@ -228,8 +245,8 @@ module Mongrel2::WebSocket
|
|
228
245
|
end
|
229
246
|
|
230
247
|
|
231
|
-
### Create a Mongrel2::WebSocket::Handshake that will respond to the same
|
232
|
-
### the receiver.
|
248
|
+
### Create a Mongrel2::WebSocket::Handshake that will respond to the same
|
249
|
+
### server/connection as the receiver.
|
233
250
|
def response( protocol=nil )
|
234
251
|
@response = super() unless @response
|
235
252
|
if protocol
|
@@ -247,7 +264,8 @@ module Mongrel2::WebSocket
|
|
247
264
|
|
248
265
|
# The server (response) handshake for a WebSocket opening handshake.
|
249
266
|
class ServerHandshake < Mongrel2::HTTPResponse
|
250
|
-
include Mongrel2::WebSocket::Constants
|
267
|
+
include Mongrel2::WebSocket::Constants,
|
268
|
+
Mongrel2::WebSocket::Methods
|
251
269
|
|
252
270
|
### Create a server handshake frame from the given client +handshake+.
|
253
271
|
def self::from_request( handshake )
|
@@ -287,7 +305,8 @@ module Mongrel2::WebSocket
|
|
287
305
|
# WebSocket frame class; this is used for both requests and responses in
|
288
306
|
# WebSocket services.
|
289
307
|
class Frame < Mongrel2::Request
|
290
|
-
include Mongrel2::WebSocket::Constants
|
308
|
+
include Mongrel2::WebSocket::Constants,
|
309
|
+
Mongrel2::WebSocket::Methods
|
291
310
|
|
292
311
|
# The default frame header flags: FIN + CLOSE
|
293
312
|
DEFAULT_FLAGS = FIN_FLAG | OPCODE[:close]
|
@@ -409,8 +428,14 @@ module Mongrel2::WebSocket
|
|
409
428
|
### Set the frame's opcode to +code+, which should be either a numeric opcode or
|
410
429
|
### its equivalent name (i.e., :continuation, :text, :binary, :close, :ping, :pong)
|
411
430
|
def opcode=( code )
|
412
|
-
opcode =
|
413
|
-
|
431
|
+
opcode = nil
|
432
|
+
|
433
|
+
if code.is_a?( Numeric )
|
434
|
+
opcode = Integer( code )
|
435
|
+
else
|
436
|
+
opcode = OPCODE[ code.to_sym ] or
|
437
|
+
raise ArgumentError, "unknown opcode %p" % [ code ]
|
438
|
+
end
|
414
439
|
|
415
440
|
self.flags ^= ( self.flags & OPCODE_BITMASK )
|
416
441
|
self.flags |= opcode
|
@@ -542,12 +567,7 @@ module Mongrel2::WebSocket
|
|
542
567
|
|
543
568
|
|
544
569
|
### Create a frame in response to the receiving Frame (i.e., with the same
|
545
|
-
### Mongrel2 connection ID and sender).
|
546
|
-
### status, Sec-WebSocket-Accept:, Connection, and Upgrade: headers based on the
|
547
|
-
### receiver. If +protocol+ is non-nil, and it matches one of the
|
548
|
-
### values listed in 'Sec-WebSocket-Protocol', it will be set as the
|
549
|
-
### Handshake's Sec-WebSocket-Protocol header. If it is non-nil, but doesn't
|
550
|
-
### match one of the request's values, a Mongrel2::WebSocket::Error is raised.
|
570
|
+
### Mongrel2 connection ID and sender).
|
551
571
|
def response( *flags )
|
552
572
|
unless @response
|
553
573
|
@response = super()
|
@@ -558,7 +578,7 @@ module Mongrel2::WebSocket
|
|
558
578
|
@response.opcode = :pong
|
559
579
|
IO.copy_stream( self.payload, @response.payload, 4096 )
|
560
580
|
else
|
561
|
-
@response.opcode = self.
|
581
|
+
@response.opcode = self.numeric_opcode
|
562
582
|
end
|
563
583
|
|
564
584
|
# Set flags in the response
|
@@ -592,7 +612,7 @@ module Mongrel2::WebSocket
|
|
592
612
|
when :continuation, :text, :binary, :close, :ping, :pong
|
593
613
|
self.opcode = flag
|
594
614
|
when Integer
|
595
|
-
self.log.debug " setting Integer flags directly: 0b%08b" % [
|
615
|
+
self.log.debug " setting Integer flags directly: 0b%08b" % [ flag ]
|
596
616
|
self.flags |= flag
|
597
617
|
else
|
598
618
|
raise ArgumentError, "Don't know what the %p flag is." % [ flag ]
|
data/spec/lib/constants.rb
CHANGED
@@ -112,6 +112,11 @@ describe Mongrel2::WebSocket do
|
|
112
112
|
}.to raise_error( Mongrel2::WebSocket::HandshakeError, /map_updates/i )
|
113
113
|
end
|
114
114
|
|
115
|
+
it "has a socket identifier" do
|
116
|
+
handshake = @factory.handshake( '/websock', 'echo', 'superecho' )
|
117
|
+
handshake.socket_id.should == "#{handshake.sender_id}:#{handshake.conn_id}"
|
118
|
+
end
|
119
|
+
|
115
120
|
end
|
116
121
|
|
117
122
|
|
@@ -169,6 +174,45 @@ describe Mongrel2::WebSocket do
|
|
169
174
|
@factory.pong( '/websock' ).opcode.should == :pong
|
170
175
|
end
|
171
176
|
|
177
|
+
it "knows that its opcode is one of the reserved ones if it's 0x3" do
|
178
|
+
@factory.create( '/websocket', '', 0x3 ).opcode.should == :reserved
|
179
|
+
end
|
180
|
+
|
181
|
+
it "knows that its opcode is one of the reserved ones if it's 0x4" do
|
182
|
+
@factory.create( '/websocket', '', 0x4 ).opcode.should == :reserved
|
183
|
+
end
|
184
|
+
|
185
|
+
it "knows that its opcode is one of the reserved ones if it's 0xB" do
|
186
|
+
@factory.create( '/websocket', '', 0xB ).opcode.should == :reserved
|
187
|
+
end
|
188
|
+
|
189
|
+
it "knows that its opcode is one of the reserved ones if it's 0xD" do
|
190
|
+
@factory.create( '/websocket', '', 0xD ).opcode.should == :reserved
|
191
|
+
end
|
192
|
+
|
193
|
+
it "knows that its opcode is one of the reserved ones if it's 0xF" do
|
194
|
+
@factory.create( '/websocket', '', 0xF ).opcode.should == :reserved
|
195
|
+
end
|
196
|
+
|
197
|
+
it "allows its opcode to be set Symbolically" do
|
198
|
+
frame = @factory.text( '/websocket', 'data' )
|
199
|
+
frame.opcode = :binary
|
200
|
+
frame.numeric_opcode.should == OPCODE[:binary]
|
201
|
+
end
|
202
|
+
|
203
|
+
it "allows its opcode to be set Numerically" do
|
204
|
+
frame = @factory.binary( '/websocket', 'data' )
|
205
|
+
frame.opcode = :text
|
206
|
+
frame.numeric_opcode.should == OPCODE[:text]
|
207
|
+
end
|
208
|
+
|
209
|
+
it "allows its opcode to be set to one of the reserved opcodes Numerically" do
|
210
|
+
frame = @factory.binary( '/websocket', 'data' )
|
211
|
+
frame.opcode = 0xC
|
212
|
+
frame.opcode.should == :reserved
|
213
|
+
frame.numeric_opcode.should == 0xC
|
214
|
+
end
|
215
|
+
|
172
216
|
it "knows that its RSV1 flag is set if its FLAG header includes that bit" do
|
173
217
|
@factory.ping( '/websock', 'test', :rsv1 ).should be_rsv1()
|
174
218
|
end
|
@@ -240,6 +284,21 @@ describe Mongrel2::WebSocket do
|
|
240
284
|
result.payload.read.should == ''
|
241
285
|
end
|
242
286
|
|
287
|
+
it "allows reserved opcodes to be specified when creating a response" do
|
288
|
+
frame = @factory.text( '/websock', "some bad data" )
|
289
|
+
|
290
|
+
result = frame.response( 0xB )
|
291
|
+
|
292
|
+
result.should be_a( Mongrel2::WebSocket::Frame )
|
293
|
+
result.sender_id.should == frame.sender_id
|
294
|
+
result.conn_id.should == frame.conn_id
|
295
|
+
result.opcode.should == :reserved
|
296
|
+
result.numeric_opcode.should == 0xB
|
297
|
+
|
298
|
+
result.payload.rewind
|
299
|
+
result.payload.read.should == ''
|
300
|
+
end
|
301
|
+
|
243
302
|
it "can be streamed in chunks instead of read all at once" do
|
244
303
|
data = BINARY_DATA * 256
|
245
304
|
binary = @factory.binary( '/websock', data, :fin )
|
@@ -251,6 +310,11 @@ describe Mongrel2::WebSocket do
|
|
251
310
|
]
|
252
311
|
end
|
253
312
|
|
313
|
+
it "has a socket identifier" do
|
314
|
+
frame = @factory.text( '/websock', "data" )
|
315
|
+
frame.socket_id.should == "#{frame.sender_id}:#{frame.conn_id}"
|
316
|
+
end
|
317
|
+
|
254
318
|
end
|
255
319
|
|
256
320
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongrel2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.35.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
|
37
37
|
Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
|
38
38
|
cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
39
|
-
date: 2012-12-
|
39
|
+
date: 2012-12-14 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: nokogiri
|
metadata.gz.sig
CHANGED
Binary file
|