websocket-driver 0.9.1-java → 0.9.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 +9 -0
- data/lib/websocket/driver/client.rb +1 -0
- data/lib/websocket/driver/draft75.rb +24 -3
- data/lib/websocket/driver/draft76.rb +2 -11
- data/lib/websocket/driver/hybi.rb +18 -4
- data/lib/websocket/driver/server.rb +1 -0
- data/lib/websocket/driver/stream_reader.rb +6 -0
- data/lib/websocket/driver.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6845fa1d666f5854bad3d57dfea229028ba1317a3d754251ec44766e3415a985
|
|
4
|
+
data.tar.gz: e8c2e7c3f00c9fe552e7371d9d84002758bca2c51801b509d87f55941d7c4e70
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c97b51a2c5a513d004b6fa910ff35868d1e505072682267ecf1b73f9dbcbb5dd5c0ec718e0faedf094527c118c8dbe6f6eaf59dbca08e87f98cbe6abbcf721c4
|
|
7
|
+
data.tar.gz: 4d644f0b2676f38b37c06cfe99228a3a62c67264a98bd7bca047febae91bc203e206caf9aa1c967e1d8b3e5f95163ac970b99eea10784f0032b6bd8bdaca3770
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
### 0.9.2 / 2026-12-01
|
|
2
|
+
|
|
3
|
+
- Correctly handle data written to the driver before `start` is called, for all
|
|
4
|
+
protocol versions
|
|
5
|
+
- Handle messages received after calling `close` without buffering data beyond
|
|
6
|
+
the `max_length` limit
|
|
7
|
+
- Correctly enforce the `max_length` limit when buffering draft-75/76 input
|
|
8
|
+
- Cap the amount of data buffered by the stream reader to `max_length`
|
|
9
|
+
|
|
1
10
|
### 0.9.1 / 2026-11-26
|
|
2
11
|
|
|
3
12
|
- Stop buffering incoming data after a socket has failed or been closed
|
|
@@ -5,7 +5,11 @@ module WebSocket
|
|
|
5
5
|
def initialize(socket, options = {})
|
|
6
6
|
super
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
input = (socket.env['rack.input'] || StringIO.new('')).read
|
|
9
|
+
input = input.dup if input.frozen?
|
|
10
|
+
@stage = -1
|
|
11
|
+
@body = input.force_encoding(Encoding::BINARY)
|
|
12
|
+
|
|
9
13
|
@closing = false
|
|
10
14
|
|
|
11
15
|
@headers['Upgrade'] = 'WebSocket'
|
|
@@ -18,6 +22,12 @@ module WebSocket
|
|
|
18
22
|
'hixie-75'
|
|
19
23
|
end
|
|
20
24
|
|
|
25
|
+
def start
|
|
26
|
+
return false unless super
|
|
27
|
+
handle_buffered_body
|
|
28
|
+
true
|
|
29
|
+
end
|
|
30
|
+
|
|
21
31
|
def close(reason = nil, code = nil)
|
|
22
32
|
return false if @ready_state == 3
|
|
23
33
|
@ready_state = 3
|
|
@@ -34,7 +44,8 @@ module WebSocket
|
|
|
34
44
|
case @stage
|
|
35
45
|
when -1 then
|
|
36
46
|
@body << octet
|
|
37
|
-
|
|
47
|
+
handle_buffered_body
|
|
48
|
+
return close if @body.size > @max_length
|
|
38
49
|
|
|
39
50
|
when 0 then
|
|
40
51
|
parse_leading_byte(octet)
|
|
@@ -68,7 +79,10 @@ module WebSocket
|
|
|
68
79
|
emit(:message, MessageEvent.new(Driver.encode(@buffer, Encoding::UTF_8)))
|
|
69
80
|
else
|
|
70
81
|
@buffer << octet
|
|
71
|
-
|
|
82
|
+
if @buffer.size > @max_length
|
|
83
|
+
@stage = 4
|
|
84
|
+
close
|
|
85
|
+
end
|
|
72
86
|
end
|
|
73
87
|
end
|
|
74
88
|
end
|
|
@@ -89,6 +103,13 @@ module WebSocket
|
|
|
89
103
|
headers.join("\r\n")
|
|
90
104
|
end
|
|
91
105
|
|
|
106
|
+
def handle_buffered_body
|
|
107
|
+
return unless @started
|
|
108
|
+
@stage = 0
|
|
109
|
+
open
|
|
110
|
+
parse(@body)
|
|
111
|
+
end
|
|
112
|
+
|
|
92
113
|
def parse_leading_byte(octet)
|
|
93
114
|
if (octet & 0x80) == 0x80
|
|
94
115
|
@length = 0
|
|
@@ -6,10 +6,6 @@ module WebSocket
|
|
|
6
6
|
|
|
7
7
|
def initialize(socket, options = {})
|
|
8
8
|
super
|
|
9
|
-
input = (@socket.env['rack.input'] || StringIO.new('')).read
|
|
10
|
-
input = input.dup if input.frozen?
|
|
11
|
-
@stage = -1
|
|
12
|
-
@body = input.force_encoding(Encoding::BINARY)
|
|
13
9
|
|
|
14
10
|
@headers.clear
|
|
15
11
|
@headers['Upgrade'] = 'WebSocket'
|
|
@@ -22,12 +18,6 @@ module WebSocket
|
|
|
22
18
|
'hixie-76'
|
|
23
19
|
end
|
|
24
20
|
|
|
25
|
-
def start
|
|
26
|
-
return false unless super
|
|
27
|
-
send_handshake_body
|
|
28
|
-
true
|
|
29
|
-
end
|
|
30
|
-
|
|
31
21
|
def close(reason = nil, code = nil)
|
|
32
22
|
return false if @ready_state == 3
|
|
33
23
|
@socket.write([0xFF, 0x00].pack('C*')) if @ready_state == 1
|
|
@@ -54,13 +44,14 @@ module WebSocket
|
|
|
54
44
|
end
|
|
55
45
|
|
|
56
46
|
def handshake_signature
|
|
47
|
+
return nil unless @key_values
|
|
57
48
|
return nil unless @body.bytesize >= BODY_SIZE
|
|
58
49
|
|
|
59
50
|
head = @body[0...BODY_SIZE]
|
|
60
51
|
Digest::MD5.digest((@key_values + [head]).pack('N2A*'))
|
|
61
52
|
end
|
|
62
53
|
|
|
63
|
-
def
|
|
54
|
+
def handle_buffered_body
|
|
64
55
|
return unless signature = handshake_signature
|
|
65
56
|
@socket.write(signature)
|
|
66
57
|
@stage = 0
|
|
@@ -60,7 +60,7 @@ module WebSocket
|
|
|
60
60
|
super
|
|
61
61
|
|
|
62
62
|
@extensions = ::WebSocket::Extensions.new(:max_length => @max_length)
|
|
63
|
-
@stage =
|
|
63
|
+
@stage = -1
|
|
64
64
|
@masking = options[:masking]
|
|
65
65
|
@protocols = options[:protocols] || []
|
|
66
66
|
@protocols = @protocols.strip.split(/ *, */) if String === @protocols
|
|
@@ -83,15 +83,27 @@ module WebSocket
|
|
|
83
83
|
"hybi-#{ VERSION }"
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
+
def start
|
|
87
|
+
return false unless super
|
|
88
|
+
@stage = 0
|
|
89
|
+
open
|
|
90
|
+
parse('')
|
|
91
|
+
true
|
|
92
|
+
end
|
|
93
|
+
|
|
86
94
|
def add_extension(extension)
|
|
87
95
|
@extensions.add(extension)
|
|
88
96
|
true
|
|
89
97
|
end
|
|
90
98
|
|
|
91
99
|
def parse(chunk)
|
|
92
|
-
return unless @reader
|
|
100
|
+
return unless @ready_state <= 2 and @reader
|
|
93
101
|
|
|
94
102
|
@reader.put(chunk)
|
|
103
|
+
if @reader.size > @max_length
|
|
104
|
+
return fail(:too_large, 'WebSocket frame length too large')
|
|
105
|
+
end
|
|
106
|
+
|
|
95
107
|
buffer = true
|
|
96
108
|
|
|
97
109
|
while buffer
|
|
@@ -265,7 +277,7 @@ module WebSocket
|
|
|
265
277
|
@stage = 5
|
|
266
278
|
@extensions.close
|
|
267
279
|
|
|
268
|
-
frame(reason, :close, code) if @ready_state
|
|
280
|
+
frame(reason, :close, code) if @ready_state == 1 or @ready_state == 2
|
|
269
281
|
@ready_state = 3
|
|
270
282
|
|
|
271
283
|
emit(:error, ProtocolError.new(reason)) if error
|
|
@@ -273,7 +285,7 @@ module WebSocket
|
|
|
273
285
|
end
|
|
274
286
|
|
|
275
287
|
def fail(type, message)
|
|
276
|
-
return if @ready_state >
|
|
288
|
+
return if @ready_state > 2
|
|
277
289
|
code = (Symbol === type) ? ERRORS[type] : type
|
|
278
290
|
shutdown(code, message, true)
|
|
279
291
|
end
|
|
@@ -399,6 +411,8 @@ module WebSocket
|
|
|
399
411
|
end
|
|
400
412
|
|
|
401
413
|
def emit_message
|
|
414
|
+
return if @ready_state > 1
|
|
415
|
+
|
|
402
416
|
message = @extensions.process_incoming_message(@message)
|
|
403
417
|
@message = nil
|
|
404
418
|
|
|
@@ -10,6 +10,10 @@ module WebSocket
|
|
|
10
10
|
@offset = 0
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
def size
|
|
14
|
+
@buffer.bytesize
|
|
15
|
+
end
|
|
16
|
+
|
|
13
17
|
def put(chunk)
|
|
14
18
|
return unless chunk and chunk.bytesize > 0
|
|
15
19
|
@buffer << chunk.force_encoding(Encoding::BINARY)
|
|
@@ -34,6 +38,8 @@ module WebSocket
|
|
|
34
38
|
@offset += 1
|
|
35
39
|
yield octet
|
|
36
40
|
end
|
|
41
|
+
|
|
42
|
+
prune
|
|
37
43
|
end
|
|
38
44
|
|
|
39
45
|
private
|
data/lib/websocket/driver.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: websocket-driver
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.2
|
|
5
5
|
platform: java
|
|
6
6
|
authors:
|
|
7
7
|
- James Coglan
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-12-01 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: base64
|