websocket-driver 0.3.1-java → 0.3.2-java
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/websocket/driver.rb +3 -1
- data/lib/websocket/driver/draft75.rb +10 -2
- data/lib/websocket/driver/hybi.rb +21 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bec6e8f91e91b51b1cc98336ebcceee6f32e494
|
4
|
+
data.tar.gz: 53c2c5fbacfe1a4d98e3f67c8e0729a75f77070a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb6c2cddd455a97acab01a17cefd141868210431046c2b99a6ccc5649bb249fae737e7d090039b035b30c22ae871510c0c438a9c7571469d81c02a98d9d420ac
|
7
|
+
data.tar.gz: eaec2701ec99d6fff46d71fd902619382ccd932cd0c53f4e13e68c223b2fd359adfa58ad7b58ee18b02575ea2d87285a42a0cef8fc77eabe407330ae58c82594
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 0.3.2 / 2013-12-29
|
2
|
+
|
3
|
+
* Expand `max_length` to cover sequences of continuation frames and `draft-{75,76}`
|
4
|
+
* Decrease default maximum frame buffer size to 64MB
|
5
|
+
* Stop parsing when the protocol enters a failure mode, to save CPU cycles
|
6
|
+
|
1
7
|
### 0.3.1 / 2013-12-03
|
2
8
|
|
3
9
|
* Add a `max_length` option to limit allowed frame size
|
data/README.md
CHANGED
@@ -213,7 +213,7 @@ The `options` argument is optional, and is a hash. It may contain the following
|
|
213
213
|
keys:
|
214
214
|
|
215
215
|
* `:max_length` - the maximum allowed size of incoming message frames, in bytes.
|
216
|
-
The default value is `2^
|
216
|
+
The default value is `2^26 - 1`, or 1 byte short of 64 MiB.
|
217
217
|
* `:protocols` - an array of strings representing acceptable subprotocols for
|
218
218
|
use over the socket. The driver will negotiate one of these to use via the
|
219
219
|
`Sec-WebSocket-Protocol` header if supported by the other peer.
|
data/lib/websocket/driver.rb
CHANGED
@@ -35,7 +35,8 @@ module WebSocket
|
|
35
35
|
require root + '/utf8_match'
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
MAX_LENGTH = 0x3ffffff
|
39
|
+
STATES = [:connecting, :open, :closing, :closed]
|
39
40
|
|
40
41
|
class ConnectEvent < Struct.new(nil) ; end
|
41
42
|
class OpenEvent < Struct.new(nil) ; end
|
@@ -60,6 +61,7 @@ module WebSocket
|
|
60
61
|
|
61
62
|
@socket = socket
|
62
63
|
@options = options
|
64
|
+
@max_length = options[:max_length] || MAX_LENGTH
|
63
65
|
@headers = Headers.new
|
64
66
|
@queue = []
|
65
67
|
@ready_state = 0
|
@@ -11,7 +11,15 @@ module WebSocket
|
|
11
11
|
'hixie-75'
|
12
12
|
end
|
13
13
|
|
14
|
+
def close(reason = nil, code = nil)
|
15
|
+
return false if @ready_state == 3
|
16
|
+
@ready_state = 3
|
17
|
+
emit(:close, CloseEvent.new(nil, nil))
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
14
21
|
def parse(buffer)
|
22
|
+
return if @ready_state > 1
|
15
23
|
buffer = buffer.bytes if buffer.respond_to?(:bytes)
|
16
24
|
|
17
25
|
buffer.each do |data|
|
@@ -28,8 +36,7 @@ module WebSocket
|
|
28
36
|
@length = value + 128 * @length
|
29
37
|
|
30
38
|
if @closing and @length.zero?
|
31
|
-
|
32
|
-
emit(:close, CloseEvent.new(nil, nil))
|
39
|
+
return close
|
33
40
|
elsif (0x80 & data) != 0x80
|
34
41
|
if @length.zero?
|
35
42
|
@stage = 0
|
@@ -49,6 +56,7 @@ module WebSocket
|
|
49
56
|
@stage = 0 if @skipped == @length
|
50
57
|
else
|
51
58
|
@buffer << data
|
59
|
+
return close if @buffer.size > @max_length
|
52
60
|
end
|
53
61
|
end
|
54
62
|
end
|
@@ -32,8 +32,6 @@ module WebSocket
|
|
32
32
|
FRAGMENTED_OPCODES = OPCODES.values_at(:continuation, :text, :binary)
|
33
33
|
OPENING_OPCODES = OPCODES.values_at(:text, :binary)
|
34
34
|
|
35
|
-
MAX_LENGTH = 0x3fffffff
|
36
|
-
|
37
35
|
ERRORS = {
|
38
36
|
:normal_closure => 1000,
|
39
37
|
:going_away => 1001,
|
@@ -54,12 +52,11 @@ module WebSocket
|
|
54
52
|
super
|
55
53
|
reset
|
56
54
|
|
57
|
-
@reader
|
58
|
-
@stage
|
59
|
-
@masking
|
60
|
-
@protocols
|
61
|
-
@protocols
|
62
|
-
@max_length = options[:max_length] || MAX_LENGTH
|
55
|
+
@reader = StreamReader.new
|
56
|
+
@stage = 0
|
57
|
+
@masking = options[:masking]
|
58
|
+
@protocols = options[:protocols] || []
|
59
|
+
@protocols = @protocols.strip.split(/\s*,\s*/) if String === @protocols
|
63
60
|
|
64
61
|
@require_masking = options[:require_masking]
|
65
62
|
@ping_callbacks = {}
|
@@ -101,6 +98,9 @@ module WebSocket
|
|
101
98
|
emit_frame
|
102
99
|
@stage = 0
|
103
100
|
end
|
101
|
+
|
102
|
+
else
|
103
|
+
buffer = nil
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
@@ -222,6 +222,7 @@ module WebSocket
|
|
222
222
|
def shutdown(code, reason)
|
223
223
|
frame(reason, :close, code)
|
224
224
|
@ready_state = 3
|
225
|
+
@stage = 5
|
225
226
|
emit(:close, CloseEvent.new(code, reason))
|
226
227
|
end
|
227
228
|
|
@@ -268,7 +269,8 @@ module WebSocket
|
|
268
269
|
|
269
270
|
@length = (data & LENGTH)
|
270
271
|
|
271
|
-
if @length <= 125
|
272
|
+
if @length >= 0 and @length <= 125
|
273
|
+
return unless check_frame_length
|
272
274
|
@stage = @masked ? 3 : 4
|
273
275
|
else
|
274
276
|
@length_size = (@length == 126) ? 2 : 8
|
@@ -283,13 +285,20 @@ module WebSocket
|
|
283
285
|
return fail(:protocol_error, "Received control frame having too long payload: #{@length}")
|
284
286
|
end
|
285
287
|
|
286
|
-
|
287
|
-
return fail(:too_large, 'WebSocket frame length too large')
|
288
|
-
end
|
288
|
+
return unless check_frame_length
|
289
289
|
|
290
290
|
@stage = @masked ? 3 : 4
|
291
291
|
end
|
292
292
|
|
293
|
+
def check_frame_length
|
294
|
+
if @buffer.size + @length > @max_length
|
295
|
+
fail(:too_large, 'WebSocket frame length too large')
|
296
|
+
false
|
297
|
+
else
|
298
|
+
true
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
293
302
|
def emit_frame
|
294
303
|
payload = @masked ? Mask.mask(@payload, @mask) : @payload
|
295
304
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: websocket-driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- James Coglan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|