protocol-websocket 0.11.0 → 0.12.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/websocket/connection.rb +17 -20
- data/lib/protocol/websocket/frame.rb +26 -13
- data/lib/protocol/websocket/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +4 -6
- metadata.gz.sig +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/protocol/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 336e62c38fbb57000bf3183e14f750224706504cd8777bbc7d09505f71a0d65e
|
4
|
+
data.tar.gz: 2bb63e4bab32ba833f90e5f2857ae198a4f0b9aa66404044ac192e9bcc04c726
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eba17e42ae64f93fd5d427245b916fb25c6c09971db2d15969d6b8e29aaea22fb1ab39d52aff19fb46157003bf5c277b0aab1194f00a3fc04532fb1bfa1ab3ca
|
7
|
+
data.tar.gz: e228e38de1c954c9c7c506bc73c94194eea02bb51ee5d0baaae61b98820f831a409970c00a74846a70d0a7642ea807d7e6c09734c388d9634379f0e1bef659cc
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -61,8 +61,17 @@ module Protocol
|
|
61
61
|
return self
|
62
62
|
end
|
63
63
|
|
64
|
+
# If not already closed, transition the connection to the closed state and send a close frame.
|
64
65
|
def close!(...)
|
65
|
-
@state
|
66
|
+
unless @state == :closed
|
67
|
+
@state = :closed
|
68
|
+
|
69
|
+
begin
|
70
|
+
send_close(...)
|
71
|
+
rescue
|
72
|
+
# Ignore errors.
|
73
|
+
end
|
74
|
+
end
|
66
75
|
|
67
76
|
return self
|
68
77
|
end
|
@@ -71,16 +80,9 @@ module Protocol
|
|
71
80
|
@state == :closed
|
72
81
|
end
|
73
82
|
|
83
|
+
# Immediately transition the connection to the closed state and close the underlying connection.
|
74
84
|
def close(...)
|
75
|
-
|
76
|
-
close!
|
77
|
-
|
78
|
-
begin
|
79
|
-
send_close(...)
|
80
|
-
rescue
|
81
|
-
# Ignore.
|
82
|
-
end
|
83
|
-
end
|
85
|
+
close!(...)
|
84
86
|
|
85
87
|
@framer.close
|
86
88
|
end
|
@@ -101,11 +103,9 @@ module Protocol
|
|
101
103
|
return frame
|
102
104
|
rescue ProtocolError => error
|
103
105
|
close(error.code, error.message)
|
104
|
-
|
105
106
|
raise
|
106
|
-
rescue
|
107
|
-
close(Error::PROTOCOL_ERROR,
|
108
|
-
|
107
|
+
rescue => error
|
108
|
+
close(Error::PROTOCOL_ERROR, error.message)
|
109
109
|
raise
|
110
110
|
end
|
111
111
|
|
@@ -142,11 +142,8 @@ module Protocol
|
|
142
142
|
def receive_close(frame)
|
143
143
|
code, reason = frame.unpack
|
144
144
|
|
145
|
-
#
|
146
|
-
|
147
|
-
close!
|
148
|
-
send_close(code, reason)
|
149
|
-
end
|
145
|
+
# On receiving a close frame, we must enter the closed state:
|
146
|
+
close!(code, reason)
|
150
147
|
|
151
148
|
if code and code != Error::NO_ERROR
|
152
149
|
raise ClosedError.new reason, code
|
@@ -202,6 +199,7 @@ module Protocol
|
|
202
199
|
write_frame(@writer.pack_binary_frame(buffer, **options))
|
203
200
|
end
|
204
201
|
|
202
|
+
# Send a control frame with data containing a specified control sequence to begin the closing handshake. Does not close the connection, until the remote end responds with a close frame.
|
205
203
|
def send_close(code = Error::NO_ERROR, reason = "")
|
206
204
|
frame = CloseFrame.new(mask: @mask)
|
207
205
|
frame.pack(code, reason)
|
@@ -246,7 +244,6 @@ module Protocol
|
|
246
244
|
end
|
247
245
|
rescue ProtocolError => error
|
248
246
|
close(error.code, error.message)
|
249
|
-
|
250
247
|
raise
|
251
248
|
end
|
252
249
|
end
|
@@ -86,6 +86,30 @@ module Protocol
|
|
86
86
|
attr_accessor :length
|
87
87
|
attr_accessor :payload
|
88
88
|
|
89
|
+
if IO.const_defined?(:Buffer) && IO::Buffer.respond_to?(:for) && IO::Buffer.method_defined?(:xor!)
|
90
|
+
private def mask_xor(data, mask)
|
91
|
+
buffer = data.dup
|
92
|
+
mask_buffer = IO::Buffer.for(mask)
|
93
|
+
|
94
|
+
IO::Buffer.for(buffer) do |buffer|
|
95
|
+
buffer.xor!(mask_buffer)
|
96
|
+
end
|
97
|
+
|
98
|
+
return buffer
|
99
|
+
end
|
100
|
+
else
|
101
|
+
warn "IO::Buffer not available, falling back to slow implementation of mask_xor!"
|
102
|
+
private def mask_xor(data, mask)
|
103
|
+
result = String.new(encoding: Encoding::BINARY)
|
104
|
+
|
105
|
+
for i in 0...data.bytesize do
|
106
|
+
result << (data.getbyte(i) ^ mask.getbyte(i % 4))
|
107
|
+
end
|
108
|
+
|
109
|
+
return result
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
89
113
|
def pack(data = "")
|
90
114
|
length = data.bytesize
|
91
115
|
|
@@ -94,12 +118,7 @@ module Protocol
|
|
94
118
|
end
|
95
119
|
|
96
120
|
if @mask
|
97
|
-
@payload =
|
98
|
-
|
99
|
-
for i in 0...data.bytesize do
|
100
|
-
@payload << (data.getbyte(i) ^ mask.getbyte(i % 4))
|
101
|
-
end
|
102
|
-
|
121
|
+
@payload = mask_xor(data, mask)
|
103
122
|
@length = length
|
104
123
|
else
|
105
124
|
@payload = data
|
@@ -111,13 +130,7 @@ module Protocol
|
|
111
130
|
|
112
131
|
def unpack
|
113
132
|
if @mask and !@payload.empty?
|
114
|
-
|
115
|
-
|
116
|
-
for i in 0...@payload.bytesize do
|
117
|
-
data << (@payload.getbyte(i) ^ @mask.getbyte(i % 4))
|
118
|
-
end
|
119
|
-
|
120
|
-
return data
|
133
|
+
return mask_xor(@payload, @mask)
|
121
134
|
else
|
122
135
|
return @payload
|
123
136
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-websocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -41,7 +41,7 @@ cert_chain:
|
|
41
41
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
42
42
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
43
43
|
-----END CERTIFICATE-----
|
44
|
-
date: 2023-
|
44
|
+
date: 2023-07-01 00:00:00.000000000 Z
|
45
45
|
dependencies:
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: protocol-http
|
@@ -119,8 +119,6 @@ executables: []
|
|
119
119
|
extensions: []
|
120
120
|
extra_rdoc_files: []
|
121
121
|
files:
|
122
|
-
- lib/.DS_Store
|
123
|
-
- lib/protocol/.DS_Store
|
124
122
|
- lib/protocol/websocket.rb
|
125
123
|
- lib/protocol/websocket/binary_frame.rb
|
126
124
|
- lib/protocol/websocket/close_frame.rb
|
@@ -156,14 +154,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
154
|
requirements:
|
157
155
|
- - ">="
|
158
156
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
157
|
+
version: '3.0'
|
160
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
159
|
requirements:
|
162
160
|
- - ">="
|
163
161
|
- !ruby/object:Gem::Version
|
164
162
|
version: '0'
|
165
163
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
164
|
+
rubygems_version: 3.5.0.dev
|
167
165
|
signing_key:
|
168
166
|
specification_version: 4
|
169
167
|
summary: A low level implementation of the WebSocket protocol.
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/.DS_Store
DELETED
Binary file
|
data/lib/protocol/.DS_Store
DELETED
Binary file
|