websocket-driver 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/lib/websocket/driver.rb +13 -20
- data/lib/websocket/driver/client.rb +1 -1
- data/lib/websocket/driver/draft75.rb +4 -2
- data/lib/websocket/driver/draft76.rb +2 -2
- data/lib/websocket/driver/hybi.rb +5 -9
- data/lib/websocket/driver/hybi/message.rb +1 -1
- data/lib/websocket/driver/proxy.rb +1 -1
- data/lib/websocket/driver/server.rb +1 -1
- data/lib/websocket/driver/stream_reader.rb +3 -3
- data/lib/websocket/http/headers.rb +2 -1
- metadata +3 -4
- data/lib/websocket/driver/utf8_match.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf0e0cdac07ab4b3dd087f8d74b36613f3e9090
|
4
|
+
data.tar.gz: 3282dd2b2f10817324192f29966b14be4611a8b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b99062bf639a33cf257613632b7f5bf9f08d514c4c7d13de6ee022e62fb749632318c534087b5800b23e958b53389b96d9efb78ca324b3a17089ab13e3817736
|
7
|
+
data.tar.gz: 51dff6847b37deb3e0451dfbbfa220ab93fb149215cae124ef4fb94b52974c891c175bbab537ac3d6cc9c6e851e95fe6db805286639bb72051e6b57ca5cd01ad
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 0.6.4 / 2016-05-20
|
2
|
+
|
3
|
+
* Amend warnings issued when running with -W2
|
4
|
+
* Make sure message strings passed in by the app are transcoded to UTF-8
|
5
|
+
* Copy strings if necessary for frozen-string compatibility
|
6
|
+
|
1
7
|
### 0.6.3 / 2015-11-06
|
2
8
|
|
3
9
|
* Reject draft-76 handshakes if their Sec-WebSocket-Key headers are invalid
|
data/README.md
CHANGED
@@ -373,7 +373,7 @@ using the `Sec-WebSocket-Protocol` mechanism. This value becomes available after
|
|
373
373
|
|
374
374
|
(The MIT License)
|
375
375
|
|
376
|
-
Copyright (c) 2010-
|
376
|
+
Copyright (c) 2010-2016 James Coglan
|
377
377
|
|
378
378
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
379
379
|
this software and associated documentation files (the 'Software'), to deal in
|
data/lib/websocket/driver.rb
CHANGED
@@ -33,13 +33,12 @@ module WebSocket
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
unless String.instance_methods.include?(:force_encoding)
|
37
|
-
require root + '/utf8_match'
|
38
|
-
end
|
39
|
-
|
40
36
|
MAX_LENGTH = 0x3ffffff
|
41
37
|
STATES = [:connecting, :open, :closing, :closed]
|
42
38
|
|
39
|
+
BINARY = 'ASCII-8BIT'
|
40
|
+
UNICODE = 'UTF-8'
|
41
|
+
|
43
42
|
ConnectEvent = Struct.new(nil)
|
44
43
|
OpenEvent = Struct.new(nil)
|
45
44
|
MessageEvent = Struct.new(:data)
|
@@ -94,13 +93,14 @@ module WebSocket
|
|
94
93
|
return false unless @ready_state == 0
|
95
94
|
response = handshake_response
|
96
95
|
return false unless response
|
97
|
-
@socket.write(
|
96
|
+
@socket.write(response)
|
98
97
|
open unless @stage == -1
|
99
98
|
true
|
100
99
|
end
|
101
100
|
|
102
101
|
def text(message)
|
103
|
-
|
102
|
+
message = message.encode(UNICODE) unless message.encoding.name == UNICODE
|
103
|
+
frame(message, :text)
|
104
104
|
end
|
105
105
|
|
106
106
|
def binary(message)
|
@@ -159,14 +159,15 @@ module WebSocket
|
|
159
159
|
case string
|
160
160
|
when Array then
|
161
161
|
string = string.pack('C*')
|
162
|
-
encoding ||=
|
162
|
+
encoding ||= BINARY
|
163
163
|
when String then
|
164
|
-
encoding ||=
|
164
|
+
encoding ||= UNICODE
|
165
|
+
end
|
166
|
+
unless string.encoding.name == encoding
|
167
|
+
string = string.dup if string.frozen?
|
168
|
+
string.force_encoding(encoding)
|
165
169
|
end
|
166
|
-
|
167
|
-
string.force_encoding(encodings[encoding]) if string.respond_to?(:force_encoding)
|
168
|
-
return nil if encoding == :utf8 and not valid_utf8?(string)
|
169
|
-
string
|
170
|
+
string.valid_encoding? ? string : nil
|
170
171
|
end
|
171
172
|
|
172
173
|
def self.validate_options(options, valid_keys)
|
@@ -177,14 +178,6 @@ module WebSocket
|
|
177
178
|
end
|
178
179
|
end
|
179
180
|
|
180
|
-
def self.valid_utf8?(string)
|
181
|
-
if defined?(UTF8_MATCH)
|
182
|
-
UTF8_MATCH =~ string ? true : false
|
183
|
-
else
|
184
|
-
string.valid_encoding?
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
181
|
def self.websocket?(env)
|
189
182
|
connection = env['HTTP_CONNECTION'] || ''
|
190
183
|
upgrade = env['HTTP_UPGRADE'] || ''
|
@@ -4,7 +4,9 @@ module WebSocket
|
|
4
4
|
class Draft75 < Driver
|
5
5
|
def initialize(socket, options = {})
|
6
6
|
super
|
7
|
-
|
7
|
+
|
8
|
+
@stage = 0
|
9
|
+
@closing = false
|
8
10
|
|
9
11
|
@headers['Upgrade'] = 'WebSocket'
|
10
12
|
@headers['Connection'] = 'Upgrade'
|
@@ -54,7 +56,7 @@ module WebSocket
|
|
54
56
|
when 2 then
|
55
57
|
if octet == 0xFF
|
56
58
|
@stage = 0
|
57
|
-
emit(:message, MessageEvent.new(Driver.encode(@buffer,
|
59
|
+
emit(:message, MessageEvent.new(Driver.encode(@buffer, UNICODE)))
|
58
60
|
else
|
59
61
|
if @length
|
60
62
|
@skipped += 1
|
@@ -8,7 +8,7 @@ module WebSocket
|
|
8
8
|
super
|
9
9
|
input = @socket.env['rack.input']
|
10
10
|
@stage = -1
|
11
|
-
@body =
|
11
|
+
@body = (input ? input.read : String.new('')).force_encoding(BINARY)
|
12
12
|
|
13
13
|
@headers.clear
|
14
14
|
@headers['Upgrade'] = 'WebSocket'
|
@@ -70,7 +70,7 @@ module WebSocket
|
|
70
70
|
|
71
71
|
def send_handshake_body
|
72
72
|
return unless signature = handshake_signature
|
73
|
-
@socket.write(
|
73
|
+
@socket.write(signature)
|
74
74
|
@stage = 0
|
75
75
|
open
|
76
76
|
parse(@body[BODY_SIZE..-1]) if @body.bytesize > BODY_SIZE
|
@@ -64,6 +64,8 @@ module WebSocket
|
|
64
64
|
@require_masking = options[:require_masking]
|
65
65
|
@ping_callbacks = {}
|
66
66
|
|
67
|
+
@frame = @message = nil
|
68
|
+
|
67
69
|
return unless @socket.respond_to?(:env)
|
68
70
|
|
69
71
|
sec_key = @socket.env['HTTP_SEC_WEBSOCKET_KEY']
|
@@ -127,10 +129,6 @@ module WebSocket
|
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
130
|
-
def text(message)
|
131
|
-
frame(message, :text)
|
132
|
-
end
|
133
|
-
|
134
132
|
def binary(message)
|
135
133
|
frame(message, :binary)
|
136
134
|
end
|
@@ -201,8 +199,6 @@ module WebSocket
|
|
201
199
|
|
202
200
|
def send_frame(frame)
|
203
201
|
length = frame.length
|
204
|
-
header = (length <= 125) ? 2 : (length <= 65535 ? 4 : 10)
|
205
|
-
offset = header + (frame.masked ? 4 : 0)
|
206
202
|
buffer = []
|
207
203
|
masked = frame.masked ? MASK : 0
|
208
204
|
|
@@ -356,7 +352,7 @@ module WebSocket
|
|
356
352
|
|
357
353
|
when OPCODES[:close] then
|
358
354
|
code = (bytesize >= 2) ? payload.unpack(PACK_FORMATS[2]).first : nil
|
359
|
-
reason = (bytesize > 2) ? Driver.encode(bytes[2..-1] || [],
|
355
|
+
reason = (bytesize > 2) ? Driver.encode(bytes[2..-1] || [], UNICODE) : nil
|
360
356
|
|
361
357
|
unless (bytesize == 0) or
|
362
358
|
(code && code >= MIN_RESERVED_ERROR && code <= MAX_RESERVED_ERROR) or
|
@@ -374,7 +370,7 @@ module WebSocket
|
|
374
370
|
frame(payload, :pong)
|
375
371
|
|
376
372
|
when OPCODES[:pong] then
|
377
|
-
message = Driver.encode(payload,
|
373
|
+
message = Driver.encode(payload, UNICODE)
|
378
374
|
callback = @ping_callbacks[message]
|
379
375
|
@ping_callbacks.delete(message)
|
380
376
|
callback.call if callback
|
@@ -391,7 +387,7 @@ module WebSocket
|
|
391
387
|
|
392
388
|
case message.opcode
|
393
389
|
when OPCODES[:text] then
|
394
|
-
payload = Driver.encode(payload,
|
390
|
+
payload = Driver.encode(payload, UNICODE)
|
395
391
|
when OPCODES[:binary]
|
396
392
|
payload = payload.bytes.to_a
|
397
393
|
end
|
@@ -6,13 +6,13 @@ module WebSocket
|
|
6
6
|
MINIMUM_AUTOMATIC_PRUNE_OFFSET = 128
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@buffer =
|
9
|
+
@buffer = String.new('').force_encoding(BINARY)
|
10
10
|
@offset = 0
|
11
11
|
end
|
12
12
|
|
13
13
|
def put(chunk)
|
14
14
|
return unless chunk and chunk.bytesize > 0
|
15
|
-
@buffer <<
|
15
|
+
@buffer << chunk.force_encoding(BINARY)
|
16
16
|
end
|
17
17
|
|
18
18
|
# Read bytes from the data:
|
@@ -42,7 +42,7 @@ module WebSocket
|
|
42
42
|
buffer_size = @buffer.bytesize
|
43
43
|
|
44
44
|
if @offset > buffer_size
|
45
|
-
@buffer =
|
45
|
+
@buffer = String.new('').force_encoding(BINARY)
|
46
46
|
else
|
47
47
|
@buffer = @buffer.byteslice(@offset, buffer_size - @offset)
|
48
48
|
end
|
@@ -39,6 +39,7 @@ module WebSocket
|
|
39
39
|
|
40
40
|
def initialize
|
41
41
|
@buffer = []
|
42
|
+
@env = {}
|
42
43
|
@headers = {}
|
43
44
|
@stage = 0
|
44
45
|
end
|
@@ -75,7 +76,7 @@ module WebSocket
|
|
75
76
|
error if @stage < 2 and @buffer.size > MAX_LINE_LENGTH
|
76
77
|
end
|
77
78
|
end
|
78
|
-
@env['rack.input'] = StringIO.new(string_buffer)
|
79
|
+
@env['rack.input'] = StringIO.new(string_buffer)
|
79
80
|
end
|
80
81
|
|
81
82
|
private
|
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.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Coglan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-extensions
|
@@ -106,7 +106,6 @@ files:
|
|
106
106
|
- lib/websocket/driver/proxy.rb
|
107
107
|
- lib/websocket/driver/server.rb
|
108
108
|
- lib/websocket/driver/stream_reader.rb
|
109
|
-
- lib/websocket/driver/utf8_match.rb
|
110
109
|
- lib/websocket/http.rb
|
111
110
|
- lib/websocket/http/headers.rb
|
112
111
|
- lib/websocket/http/request.rb
|
@@ -136,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
135
|
version: '0'
|
137
136
|
requirements: []
|
138
137
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.5.1
|
140
139
|
signing_key:
|
141
140
|
specification_version: 4
|
142
141
|
summary: WebSocket protocol handler with pluggable I/O
|
@@ -1,6 +0,0 @@
|
|
1
|
-
module WebSocket
|
2
|
-
class Driver
|
3
|
-
# http://www.w3.org/International/questions/qa-forms-utf-8.en.php
|
4
|
-
UTF8_MATCH = /^([\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/
|
5
|
-
end
|
6
|
-
end
|