protocol-websocket 0.17.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c565e42a63322140910616237842446c9faf392325569500454cff2bcfe500d
4
- data.tar.gz: db2129c90eb70609ef3b14f62c5a8f261cca9d4e5796be21c15ed24f545f3a19
3
+ metadata.gz: a0ce7a7a66a43bf2fd5ec0af4a6050feb443adb076b75b2d3037cccbd9012fa4
4
+ data.tar.gz: c672fa5bca423ca23f0b9d608d6a6e89058eaca979d939ad4e01c606b51175ed
5
5
  SHA512:
6
- metadata.gz: 68c058f51adbcadb882cfd139bc88a0dbdb0d1024d3c7cc62794796e83ab730340b72289f505f5fcd1d213cda0901f4b16aaee42c899c25ffca57e3baa057078
7
- data.tar.gz: 80121ca724e4f275a88479d4778aa35070b0ddc62660ad4acda47247a1ed7461137a5227e65ea8c3569120a0bf98ff0c0a24b33039d4cf67602b825c2289891a
6
+ metadata.gz: 598365c3df8b46fb6e79668a8d8bb452eb1e973f04f31c16346a391884448bda2d2869a6affcb2a3513a5b2dc6fab66e110f7eaebfe2593f9a50eb0bc624eb46
7
+ data.tar.gz: 4fadd3a84c98f07fbbae57a766178f85d1042500c8403e944992a3f118180c8d9952e5997c963cd26c5e843bf0e45802f2da1372a94288989ce5e1578eca0aba
checksums.yaml.gz.sig CHANGED
Binary file
@@ -4,8 +4,8 @@
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
  # Copyright, 2021, by Aurora Nockert.
6
6
 
7
- require_relative 'frame'
8
- require_relative 'message'
7
+ require_relative "frame"
8
+ require_relative "message"
9
9
 
10
10
  module Protocol
11
11
  module WebSocket
@@ -4,7 +4,7 @@
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
  # Copyright, 2021, by Aurora Nockert.
6
6
 
7
- require_relative 'frame'
7
+ require_relative "frame"
8
8
 
9
9
  module Protocol
10
10
  module WebSocket
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require 'json'
6
+ require "json"
7
7
 
8
8
  module Protocol
9
9
  module WebSocket
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2024, by Samuel Williams.
5
5
 
6
- require_relative 'coder/json'
6
+ require_relative "coder/json"
7
7
 
8
8
  module Protocol
9
9
  module WebSocket
@@ -5,8 +5,7 @@
5
5
  # Copyright, 2019, by William T. Nelson.
6
6
  # Copyright, 2021, by Aurora Nockert.
7
7
 
8
- require_relative 'framer'
9
- require 'securerandom'
8
+ require_relative "framer"
10
9
 
11
10
  module Protocol
12
11
  module WebSocket
@@ -267,7 +266,7 @@ module Protocol
267
266
  def write(message, **options)
268
267
  case message
269
268
  when String
270
- # This is a compatibility shim for the previous implementation. We may want to eventually deprecate this use case... or maybe it's convenient enough to leave it around.
269
+ # This is a compatibility shim for the previous implementation. We may want to eventually deprecate this use case... or maybe it's convenient enough to leave it around.
271
270
  if message.encoding == Encoding::UTF_8
272
271
  return send_text(message, **options)
273
272
  else
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require_relative 'frame'
6
+ require_relative "frame"
7
7
 
8
8
  module Protocol
9
9
  module WebSocket
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require 'protocol/http/error'
6
+ require "protocol/http/error"
7
7
 
8
8
  module Protocol
9
9
  module WebSocket
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2023, by Samuel Williams.
4
+ # Copyright, 2022-2024, by Samuel Williams.
5
5
 
6
- require 'zlib'
6
+ require "zlib"
7
7
 
8
8
  module Protocol
9
9
  module WebSocket
10
10
  module Extension
11
11
  module Compression
12
- NAME = 'permessage-deflate'
12
+ NAME = "permessage-deflate"
13
13
 
14
14
  # Zlib is not capable of handling < 9 window bits.
15
15
  MINIMUM_WINDOW_BITS = 9
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2023, by Samuel Williams.
4
+ # Copyright, 2022-2024, by Samuel Williams.
5
5
 
6
- require_relative 'constants'
6
+ require_relative "constants"
7
7
 
8
8
  module Protocol
9
9
  module WebSocket
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2023, by Samuel Williams.
4
+ # Copyright, 2022-2024, by Samuel Williams.
5
5
 
6
- require_relative 'constants'
6
+ require_relative "constants"
7
7
 
8
8
  module Protocol
9
9
  module WebSocket
@@ -26,7 +26,7 @@ module Protocol
26
26
  )
27
27
  end
28
28
 
29
- TRAILER = [0x00, 0x00, 0xff, 0xff].pack('C*')
29
+ TRAILER = [0x00, 0x00, 0xff, 0xff].pack("C*")
30
30
 
31
31
  def initialize(parent, context_takeover: true, window_bits: 15)
32
32
  @parent = parent
@@ -3,9 +3,9 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2022-2024, by Samuel Williams.
5
5
 
6
- require_relative 'compression/constants'
7
- require_relative 'compression/inflate'
8
- require_relative 'compression/deflate'
6
+ require_relative "compression/constants"
7
+ require_relative "compression/inflate"
8
+ require_relative "compression/deflate"
9
9
 
10
10
  module Protocol
11
11
  module WebSocket
@@ -22,13 +22,13 @@ module Protocol
22
22
  when 8..15
23
23
  header << "client_max_window_bits=#{client_max_window_bits}"
24
24
  when true
25
- header << 'client_max_window_bits'
25
+ header << "client_max_window_bits"
26
26
  else
27
27
  raise ArgumentError, "Invalid local maximum window bits!"
28
28
  end
29
29
 
30
30
  if client_no_context_takeover
31
- header << 'client_no_context_takeover'
31
+ header << "client_no_context_takeover"
32
32
  end
33
33
 
34
34
  case server_max_window_bits
@@ -41,7 +41,7 @@ module Protocol
41
41
  end
42
42
 
43
43
  if server_no_context_takeover
44
- header << 'server_no_context_takeover'
44
+ header << "server_no_context_takeover"
45
45
  end
46
46
 
47
47
  return header
@@ -3,8 +3,8 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2022-2024, by Samuel Williams.
5
5
 
6
- require_relative 'extension/compression'
7
- require_relative 'headers'
6
+ require_relative "extension/compression"
7
+ require_relative "headers"
8
8
 
9
9
  module Protocol
10
10
  module WebSocket
@@ -16,7 +16,7 @@ module Protocol
16
16
  name, *arguments = header.split(/\s*;\s*/)
17
17
 
18
18
  arguments = arguments.map do |argument|
19
- argument.split('=', 2)
19
+ argument.split("=", 2)
20
20
  end
21
21
 
22
22
  yield name, arguments
@@ -5,7 +5,7 @@
5
5
  # Copyright, 2019, by Soumya.
6
6
  # Copyright, 2021, by Aurora Nockert.
7
7
 
8
- require_relative 'error'
8
+ require_relative "error"
9
9
 
10
10
  module Protocol
11
11
  module WebSocket
@@ -178,10 +178,10 @@ module Protocol
178
178
 
179
179
  if length == 126
180
180
  buffer = stream.read(2) or raise EOFError, "Could not read length!"
181
- length = buffer.unpack('n').first
181
+ length = buffer.unpack("n").first
182
182
  elsif length == 127
183
183
  buffer = stream.read(8) or raise EOFError, "Could not read length!"
184
- length = buffer.unpack('Q>').first
184
+ length = buffer.unpack("Q>").first
185
185
  end
186
186
 
187
187
  if length > maximum_frame_size
@@ -223,12 +223,12 @@ module Protocol
223
223
  buffer << [
224
224
  (@finished ? 0b1000_0000 : 0) | (@flags << 4) | @opcode,
225
225
  (@mask ? 0b1000_0000 : 0) | short_length,
226
- ].pack('CC')
226
+ ].pack("CC")
227
227
 
228
228
  if short_length == 126
229
- buffer << [@length].pack('n')
229
+ buffer << [@length].pack("n")
230
230
  elsif short_length == 127
231
- buffer << [@length].pack('Q>')
231
+ buffer << [@length].pack("Q>")
232
232
  end
233
233
 
234
234
  buffer << @mask if @mask
@@ -3,14 +3,14 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require_relative 'frame'
6
+ require_relative "frame"
7
7
 
8
- require_relative 'continuation_frame'
9
- require_relative 'text_frame'
10
- require_relative 'binary_frame'
11
- require_relative 'close_frame'
12
- require_relative 'ping_frame'
13
- require_relative 'pong_frame'
8
+ require_relative "continuation_frame"
9
+ require_relative "text_frame"
10
+ require_relative "binary_frame"
11
+ require_relative "close_frame"
12
+ require_relative "ping_frame"
13
+ require_relative "pong_frame"
14
14
 
15
15
  module Protocol
16
16
  module WebSocket
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require 'digest/sha1'
7
- require 'securerandom'
6
+ require "digest/sha1"
7
+ require "securerandom"
8
8
 
9
9
  module Protocol
10
10
  module WebSocket
11
11
  module Headers
12
12
  # The protocol string used for the `upgrade:` header (HTTP/1) and `:protocol` pseudo-header (HTTP/2).
13
- PROTOCOL = "websocket".freeze
13
+ PROTOCOL = "websocket"
14
14
 
15
15
  # The WebSocket protocol header, used for application level protocol negotiation.
16
- SEC_WEBSOCKET_PROTOCOL = 'sec-websocket-protocol'.freeze
16
+ SEC_WEBSOCKET_PROTOCOL = "sec-websocket-protocol"
17
17
 
18
18
  # The WebSocket version header. Used for negotiating binary protocol version.
19
- SEC_WEBSOCKET_VERSION = 'sec-websocket-version'.freeze
19
+ SEC_WEBSOCKET_VERSION = "sec-websocket-version"
20
20
 
21
- SEC_WEBSOCKET_KEY = 'sec-websocket-key'.freeze
22
- SEC_WEBSOCKET_ACCEPT = 'sec-websocket-accept'.freeze
21
+ SEC_WEBSOCKET_KEY = "sec-websocket-key"
22
+ SEC_WEBSOCKET_ACCEPT = "sec-websocket-accept"
23
23
 
24
- SEC_WEBSOCKET_EXTENSIONS = 'sec-websocket-extensions'.freeze
24
+ SEC_WEBSOCKET_EXTENSIONS = "sec-websocket-extensions"
25
25
 
26
26
  module Nounce
27
27
  GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
@@ -3,8 +3,8 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2022-2024, by Samuel Williams.
5
5
 
6
- require_relative 'frame'
7
- require_relative 'coder'
6
+ require_relative "frame"
7
+ require_relative "coder"
8
8
 
9
9
  module Protocol
10
10
  module WebSocket
@@ -12,7 +12,7 @@ module Protocol
12
12
  class Message
13
13
  # Create a new message from a buffer.
14
14
  # @attribute buffer [String] The message buffer.
15
- def initialize(buffer)
15
+ def initialize(buffer = "")
16
16
  @buffer = buffer
17
17
  end
18
18
 
@@ -72,5 +72,12 @@ module Protocol
72
72
  connection.send_binary(@buffer, **options)
73
73
  end
74
74
  end
75
+
76
+ # Represents a ping message that can be sent over a WebSocket connection.
77
+ class PingMessage < Message
78
+ def send(connection)
79
+ connection.send_ping(@buffer)
80
+ end
81
+ end
75
82
  end
76
83
  end
@@ -3,8 +3,8 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require_relative 'frame'
7
- require_relative 'pong_frame'
6
+ require_relative "frame"
7
+ require_relative "pong_frame"
8
8
 
9
9
  module Protocol
10
10
  module WebSocket
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require_relative 'frame'
6
+ require_relative "frame"
7
7
 
8
8
  module Protocol
9
9
  module WebSocket
@@ -4,8 +4,8 @@
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
  # Copyright, 2021, by Aurora Nockert.
6
6
 
7
- require_relative 'frame'
8
- require_relative 'message'
7
+ require_relative "frame"
8
+ require_relative "message"
9
9
 
10
10
  module Protocol
11
11
  module WebSocket
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module WebSocket
8
- VERSION = "0.17.0"
8
+ VERSION = "0.19.0"
9
9
  end
10
10
  end
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require_relative 'websocket/version'
7
- require_relative 'websocket/framer'
8
- require_relative 'websocket/connection'
9
- require_relative 'websocket/message'
6
+ require_relative "websocket/version"
7
+ require_relative "websocket/framer"
8
+ require_relative "websocket/connection"
9
+ require_relative "websocket/message"
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.17.0
4
+ version: 0.19.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: 2024-09-11 00:00:00.000000000 Z
44
+ date: 2024-09-25 00:00:00.000000000 Z
45
45
  dependencies:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: protocol-http
@@ -79,7 +79,6 @@ files:
79
79
  - lib/protocol/websocket/frame.rb
80
80
  - lib/protocol/websocket/framer.rb
81
81
  - lib/protocol/websocket/headers.rb
82
- - lib/protocol/websocket/json_message.rb
83
82
  - lib/protocol/websocket/message.rb
84
83
  - lib/protocol/websocket/ping_frame.rb
85
84
  - lib/protocol/websocket/pong_frame.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Released under the MIT License.
4
- # Copyright, 2022-2024, by Samuel Williams.
5
-
6
- require_relative 'message'
7
-
8
- warn "Protocol::WebSocket::JSONMessage is deprecated. Use Protocol::WebSocket::TextMessage instead."
9
-
10
- module Protocol
11
- module WebSocket
12
- # @deprecated Use {TextMessage} instead.
13
- class JSONMessage < TextMessage
14
- def self.wrap(message)
15
- message
16
- end
17
-
18
- def self.generate(object)
19
- self.new(JSON.generate(object))
20
- end
21
- end
22
- end
23
- end