websocket-driver 0.7.1 → 0.7.2
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/LICENSE.md +1 -1
- data/README.md +6 -6
- data/lib/websocket/driver.rb +1 -1
- data/lib/websocket/driver/client.rb +7 -7
- data/lib/websocket/driver/draft76.rb +3 -2
- data/lib/websocket/driver/headers.rb +1 -1
- data/lib/websocket/driver/hybi.rb +9 -9
- data/lib/websocket/driver/proxy.rb +4 -4
- data/lib/websocket/driver/server.rb +3 -3
- data/lib/websocket/http/request.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d2fd69bbe4e45d93002f9896c0fe6a0a355c1a5f1220010513f1e440ff340c4
|
4
|
+
data.tar.gz: 05f36822ac52992558db10f11ed326dbabeea6db93f029f6a98b79000350c659
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0279eab6292a9d4245781a6ccf66e76932257c34e83602dfda8d385e254c8da2f48fdd545780cda8e1824b45604c4be348e1259a1bdc97e3bcaa25783c3665aa'
|
7
|
+
data.tar.gz: 16809f7d90999be91d2713e7ad8e2bee2f313eeeabb9823b85c35d5763a766aae65c58a9299154718100735cf5db4db45aa5c270eb1e52fabd00ceb40d876064
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.7.2 / 2020-05-22
|
2
|
+
|
3
|
+
- Emit `ping` and `pong` events from the `Server` driver
|
4
|
+
- Handle draft-76 handshakes correctly if the request's body is a frozen string
|
5
|
+
|
1
6
|
### 0.7.1 / 2019-06-10
|
2
7
|
|
3
8
|
- Catch any exceptions produced while generating a handshake response and send a
|
@@ -5,6 +10,7 @@
|
|
5
10
|
- Pick the RFC-6455 protocol version if the request contains any of the headers
|
6
11
|
used by that version
|
7
12
|
- Handle errors encountered while handling malformed draft-76 requests
|
13
|
+
- Change license from MIT to Apache 2.0
|
8
14
|
|
9
15
|
### 0.7.0 / 2017-09-11
|
10
16
|
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -274,33 +274,33 @@ Note that most of these methods are commands: if they produce data that should
|
|
274
274
|
be sent over the socket, they will give this to you by calling
|
275
275
|
`socket.write(string)`.
|
276
276
|
|
277
|
-
#### `driver.on :open, -> (event) {
|
277
|
+
#### `driver.on :open, -> (event) {}`
|
278
278
|
|
279
279
|
Adds a callback block to execute when the socket becomes open.
|
280
280
|
|
281
|
-
#### `driver.on :message, -> (event) {
|
281
|
+
#### `driver.on :message, -> (event) {}`
|
282
282
|
|
283
283
|
Adds a callback block to execute when a message is received. `event` will have a
|
284
284
|
`data` attribute containing either a string in the case of a text message or an
|
285
285
|
array of integers in the case of a binary message.
|
286
286
|
|
287
|
-
#### `driver.on :error, -> (event) {
|
287
|
+
#### `driver.on :error, -> (event) {}`
|
288
288
|
|
289
289
|
Adds a callback to execute when a protocol error occurs due to the other peer
|
290
290
|
sending an invalid byte sequence. `event` will have a `message` attribute
|
291
291
|
describing the error.
|
292
292
|
|
293
|
-
#### `driver.on :close, -> (event) {
|
293
|
+
#### `driver.on :close, -> (event) {}`
|
294
294
|
|
295
295
|
Adds a callback block to execute when the socket becomes closed. The `event`
|
296
296
|
object has `code` and `reason` attributes.
|
297
297
|
|
298
|
-
#### `driver.on :ping, -> (event) {
|
298
|
+
#### `driver.on :ping, -> (event) {}`
|
299
299
|
|
300
300
|
Adds a callback block to execute when a ping is received. You do not need to
|
301
301
|
handle this by sending a pong frame yourself; the driver handles this for you.
|
302
302
|
|
303
|
-
#### `driver.on :pong, -> (event) {
|
303
|
+
#### `driver.on :pong, -> (event) {}`
|
304
304
|
|
305
305
|
Adds a callback block to execute when a pong is received. If this was in
|
306
306
|
response to a ping you sent, you can also handle this event via the
|
data/lib/websocket/driver.rb
CHANGED
@@ -215,7 +215,7 @@ module WebSocket
|
|
215
215
|
def self.validate_options(options, valid_keys)
|
216
216
|
options.keys.each do |key|
|
217
217
|
unless valid_keys.include?(key)
|
218
|
-
raise ConfigurationError, "Unrecognized option: #{key.inspect}"
|
218
|
+
raise ConfigurationError, "Unrecognized option: #{ key.inspect }"
|
219
219
|
end
|
220
220
|
end
|
221
221
|
end
|
@@ -20,10 +20,10 @@ module WebSocket
|
|
20
20
|
|
21
21
|
uri = URI.parse(@socket.url)
|
22
22
|
unless VALID_SCHEMES.include?(uri.scheme)
|
23
|
-
raise URIError, "#{socket.url} is not a valid WebSocket URL"
|
23
|
+
raise URIError, "#{ socket.url } is not a valid WebSocket URL"
|
24
24
|
end
|
25
25
|
|
26
|
-
host = uri.host + (uri.port ? ":#{uri.port}" : '')
|
26
|
+
host = uri.host + (uri.port ? ":#{ uri.port }" : '')
|
27
27
|
path = (uri.path == '') ? '/' : uri.path
|
28
28
|
@pathname = path + (uri.query ? '?' + uri.query : '')
|
29
29
|
|
@@ -44,7 +44,7 @@ module WebSocket
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def version
|
47
|
-
"hybi-#{VERSION}"
|
47
|
+
"hybi-#{ VERSION }"
|
48
48
|
end
|
49
49
|
|
50
50
|
def proxy(origin, options = {})
|
@@ -73,19 +73,19 @@ module WebSocket
|
|
73
73
|
parse(@http.body)
|
74
74
|
end
|
75
75
|
|
76
|
-
private
|
76
|
+
private
|
77
77
|
|
78
78
|
def handshake_request
|
79
79
|
extensions = @extensions.generate_offer
|
80
80
|
@headers['Sec-WebSocket-Extensions'] = extensions if extensions
|
81
81
|
|
82
|
-
start = "GET #{@pathname} HTTP/1.1"
|
82
|
+
start = "GET #{ @pathname } HTTP/1.1"
|
83
83
|
headers = [start, @headers.to_s, '']
|
84
84
|
headers.join("\r\n")
|
85
85
|
end
|
86
86
|
|
87
87
|
def fail_handshake(message)
|
88
|
-
message = "Error during WebSocket handshake: #{message}"
|
88
|
+
message = "Error during WebSocket handshake: #{ message }"
|
89
89
|
@ready_state = 3
|
90
90
|
emit(:error, ProtocolError.new(message))
|
91
91
|
emit(:close, CloseEvent.new(ERRORS[:protocol_error], message))
|
@@ -96,7 +96,7 @@ module WebSocket
|
|
96
96
|
@headers = Headers.new(@http.headers)
|
97
97
|
|
98
98
|
unless @http.code == 101
|
99
|
-
return fail_handshake("Unexpected response code: #{@http.code}")
|
99
|
+
return fail_handshake("Unexpected response code: #{ @http.code }")
|
100
100
|
end
|
101
101
|
|
102
102
|
upgrade = @http['Upgrade'] || ''
|
@@ -6,9 +6,10 @@ module WebSocket
|
|
6
6
|
|
7
7
|
def initialize(socket, options = {})
|
8
8
|
super
|
9
|
-
input = @socket.env['rack.input']
|
9
|
+
input = (@socket.env['rack.input'] || StringIO.new('')).read
|
10
|
+
input = input.dup if input.frozen?
|
10
11
|
@stage = -1
|
11
|
-
@body =
|
12
|
+
@body = input.force_encoding(BINARY)
|
12
13
|
|
13
14
|
@headers.clear
|
14
15
|
@headers['Upgrade'] = 'WebSocket'
|
@@ -25,7 +25,7 @@ module WebSocket
|
|
25
25
|
return if value.nil?
|
26
26
|
key = HTTP.normalize_header(name)
|
27
27
|
return unless @sent.add?(key) or ALLOWED_DUPLICATES.include?(key)
|
28
|
-
@lines << "#{name.strip}: #{value.to_s.strip}\r\n"
|
28
|
+
@lines << "#{ name.strip }: #{ value.to_s.strip }\r\n"
|
29
29
|
end
|
30
30
|
|
31
31
|
def inspect
|
@@ -52,7 +52,7 @@ module WebSocket
|
|
52
52
|
MIN_RESERVED_ERROR = 3000
|
53
53
|
MAX_RESERVED_ERROR = 4999
|
54
54
|
|
55
|
-
PACK_FORMATS = {2 => 'n', 8 => 'Q>'}
|
55
|
+
PACK_FORMATS = { 2 => 'n', 8 => 'Q>' }
|
56
56
|
|
57
57
|
def initialize(socket, options = {})
|
58
58
|
super
|
@@ -78,7 +78,7 @@ module WebSocket
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def version
|
81
|
-
"hybi-#{VERSION}"
|
81
|
+
"hybi-#{ VERSION }"
|
82
82
|
end
|
83
83
|
|
84
84
|
def add_extension(extension)
|
@@ -228,7 +228,7 @@ module WebSocket
|
|
228
228
|
version = @socket.env['HTTP_SEC_WEBSOCKET_VERSION']
|
229
229
|
|
230
230
|
unless version == VERSION
|
231
|
-
raise ProtocolError.new("Unsupported WebSocket version: #{VERSION}")
|
231
|
+
raise ProtocolError.new("Unsupported WebSocket version: #{ VERSION }")
|
232
232
|
end
|
233
233
|
|
234
234
|
unless sec_key
|
@@ -281,17 +281,17 @@ module WebSocket
|
|
281
281
|
|
282
282
|
unless @extensions.valid_frame_rsv?(@frame)
|
283
283
|
return fail(:protocol_error,
|
284
|
-
"One or more reserved bits are on: reserved1 = #{@frame.rsv1 ? 1 : 0}" +
|
285
|
-
", reserved2 = #{@frame.rsv2 ? 1 : 0 }" +
|
286
|
-
", reserved3 = #{@frame.rsv3 ? 1 : 0 }")
|
284
|
+
"One or more reserved bits are on: reserved1 = #{ @frame.rsv1 ? 1 : 0 }" +
|
285
|
+
", reserved2 = #{ @frame.rsv2 ? 1 : 0 }" +
|
286
|
+
", reserved3 = #{ @frame.rsv3 ? 1 : 0 }")
|
287
287
|
end
|
288
288
|
|
289
289
|
unless OPCODES.values.include?(@frame.opcode)
|
290
|
-
return fail(:protocol_error, "Unrecognized frame opcode: #{@frame.opcode}")
|
290
|
+
return fail(:protocol_error, "Unrecognized frame opcode: #{ @frame.opcode }")
|
291
291
|
end
|
292
292
|
|
293
293
|
unless MESSAGE_OPCODES.include?(@frame.opcode) or @frame.final
|
294
|
-
return fail(:protocol_error, "Received fragmented control frame: opcode = #{@frame.opcode}")
|
294
|
+
return fail(:protocol_error, "Received fragmented control frame: opcode = #{ @frame.opcode }")
|
295
295
|
end
|
296
296
|
|
297
297
|
if @message and OPENING_OPCODES.include?(@frame.opcode)
|
@@ -321,7 +321,7 @@ module WebSocket
|
|
321
321
|
@stage = @frame.masked ? 3 : 4
|
322
322
|
|
323
323
|
unless MESSAGE_OPCODES.include?(@frame.opcode) or @frame.length <= 125
|
324
|
-
return fail(:protocol_error, "Received control frame having too long payload: #{@frame.length}")
|
324
|
+
return fail(:protocol_error, "Received control frame having too long payload: #{ @frame.length }")
|
325
325
|
end
|
326
326
|
|
327
327
|
return unless check_frame_length
|
@@ -4,7 +4,7 @@ module WebSocket
|
|
4
4
|
class Proxy
|
5
5
|
include EventEmitter
|
6
6
|
|
7
|
-
PORTS = {'ws' => 80, 'wss' => 443}
|
7
|
+
PORTS = { 'ws' => 80, 'wss' => 443 }
|
8
8
|
|
9
9
|
attr_reader :status, :headers
|
10
10
|
|
@@ -20,7 +20,7 @@ module WebSocket
|
|
20
20
|
@state = 0
|
21
21
|
|
22
22
|
@headers = Headers.new
|
23
|
-
@headers['Host'] = @origin.host + (@origin.port ? ":#{@origin.port}" : '')
|
23
|
+
@headers['Host'] = @origin.host + (@origin.port ? ":#{ @origin.port }" : '')
|
24
24
|
@headers['Connection'] = 'keep-alive'
|
25
25
|
@headers['Proxy-Connection'] = 'keep-alive'
|
26
26
|
|
@@ -41,7 +41,7 @@ module WebSocket
|
|
41
41
|
@state = 1
|
42
42
|
|
43
43
|
port = @origin.port || PORTS[@origin.scheme]
|
44
|
-
start = "CONNECT #{@origin.host}:#{port} HTTP/1.1"
|
44
|
+
start = "CONNECT #{ @origin.host }:#{ port } HTTP/1.1"
|
45
45
|
headers = [start, @headers.to_s, '']
|
46
46
|
|
47
47
|
@socket.write(headers.join("\r\n"))
|
@@ -58,7 +58,7 @@ module WebSocket
|
|
58
58
|
if @status == 200
|
59
59
|
emit(:connect, ConnectEvent.new)
|
60
60
|
else
|
61
|
-
message = "Can't establish a connection to the server at #{@socket.url}"
|
61
|
+
message = "Can't establish a connection to the server at #{ @socket.url }"
|
62
62
|
emit(:error, ProtocolError.new(message))
|
63
63
|
end
|
64
64
|
end
|
@@ -2,7 +2,7 @@ module WebSocket
|
|
2
2
|
class Driver
|
3
3
|
|
4
4
|
class Server < Driver
|
5
|
-
EVENTS = %w[open message error close]
|
5
|
+
EVENTS = %w[open message error close ping pong]
|
6
6
|
|
7
7
|
def initialize(socket, options = {})
|
8
8
|
super
|
@@ -17,9 +17,9 @@ module WebSocket
|
|
17
17
|
def url
|
18
18
|
return nil unless e = env
|
19
19
|
|
20
|
-
url = "ws://#{e['HTTP_HOST']}"
|
20
|
+
url = "ws://#{ e['HTTP_HOST'] }"
|
21
21
|
url << e['PATH_INFO']
|
22
|
-
url << "?#{e['QUERY_STRING']}" unless e['QUERY_STRING'] == ''
|
22
|
+
url << "?#{ e['QUERY_STRING'] }" unless e['QUERY_STRING'] == ''
|
23
23
|
url
|
24
24
|
end
|
25
25
|
|
@@ -30,11 +30,11 @@ module WebSocket
|
|
30
30
|
super
|
31
31
|
@headers.each do |name, value|
|
32
32
|
rack_name = name.upcase.gsub(/-/, '_')
|
33
|
-
rack_name = "HTTP_#{rack_name}" unless RESERVED_HEADERS.include?(name)
|
33
|
+
rack_name = "HTTP_#{ rack_name }" unless RESERVED_HEADERS.include?(name)
|
34
34
|
@env[rack_name] = value
|
35
35
|
end
|
36
36
|
if host = @env['HTTP_HOST']
|
37
|
-
uri = URI.parse("http://#{host}")
|
37
|
+
uri = URI.parse("http://#{ host }")
|
38
38
|
@env['SERVER_NAME'] = uri.host
|
39
39
|
@env['SERVER_PORT'] = uri.port.to_s
|
40
40
|
end
|
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.7.
|
4
|
+
version: 0.7.2
|
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: 2020-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-extensions
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
|
-
rubygems_version: 3.
|
138
|
+
rubygems_version: 3.1.2
|
139
139
|
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: WebSocket protocol handler with pluggable I/O
|