async-websocket 0.22.1 → 0.23.1

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: 7085740fa3b6603dca33b7c3418b328e49e48c0dbd0a87fbbeca022d01bdf58b
4
- data.tar.gz: 564d3e010cd045962248196897deef0560f601d560e7fa30a9f34dbdcb8226bc
3
+ metadata.gz: a25d76b4b6474985857f1e8dc6bcc69f556349f08ccc1fab8d5c4136306d9fa8
4
+ data.tar.gz: 070f7118ec8e2674ec9b4a3952db3f0c7050472a991c5c35668964f5c5ce1bc4
5
5
  SHA512:
6
- metadata.gz: 1f99a5885889b5f020e47d5aa82341aafa3d838cb8f189caa95a6aec80b5175a5f486be9ef0ec1cb3bc75d2c867e88737f0dbf3c7f7585cd21259afb4a0f9e73
7
- data.tar.gz: f0d64ead515fbbd534b453c8acc5d3d0f02b3a413f6740f931b66e14573a78f8576039206ab5acf33681b44f6b2d42c27e8d98cc1ba3aa5e64fc4c76ac323c9b
6
+ metadata.gz: 63a54f18c629a495d9fc8b184f4ff09ba7b8a42b2fab96f2104f002fff10f67f0b7587cb76b9129d41a40313a769e374bf127f54ed377b8d879f315c0bdbccca
7
+ data.tar.gz: 733b864a850c94c88724607e562244445fd4c1b16645b2a83d0499ece0b89a0d8cb47da2ffdc70f11c091badc9e8baf87b32a55e929912d8b363ecf75cc39dc1
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2022, by Samuel Williams.
5
- # Copyright, 2021, by Aurora.
4
+ # Copyright, 2021-2023, by Samuel Williams.
5
+ # Copyright, 2021, by Aurora Nockert.
6
6
 
7
7
  require_relative '../connection'
8
8
  require_relative '../response'
@@ -35,7 +35,6 @@ module Async
35
35
  end
36
36
 
37
37
  response = Response.for(request, headers, protocol: protocol, **options) do |stream|
38
-
39
38
  framer = Protocol::WebSocket::Framer.new(stream)
40
39
  connection = handler.call(framer, protocol, extensions)
41
40
 
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2022, by Samuel Williams.
4
+ # Copyright, 2015-2023, by Samuel Williams.
5
+ # Copyright, 2019, by Bryan Powell.
6
+ # Copyright, 2019, by Janko Marohnić.
5
7
 
6
8
  require_relative 'request'
7
9
  require_relative 'connection'
@@ -12,6 +14,8 @@ require 'protocol/http/middleware'
12
14
 
13
15
  require 'async/http/client'
14
16
 
17
+ require 'delegate'
18
+
15
19
  module Async
16
20
  module WebSocket
17
21
  # This is a basic synchronous websocket client:
@@ -31,13 +35,29 @@ module Async
31
35
  end
32
36
  end
33
37
 
38
+ class ClientCloseDecorator < SimpleDelegator
39
+ def initialize(client, connection)
40
+ @client = client
41
+ super(connection)
42
+ end
43
+
44
+ def close
45
+ super
46
+
47
+ if @client
48
+ @client.close
49
+ @client = nil
50
+ end
51
+ end
52
+ end
53
+
34
54
  # @return [Connection] an open websocket connection to the given endpoint.
35
55
  def self.connect(endpoint, *arguments, **options, &block)
36
56
  client = self.open(endpoint, *arguments)
37
57
  connection = client.connect(endpoint.authority, endpoint.path, **options)
38
-
39
- return connection unless block_given?
40
-
58
+
59
+ return ClientCloseDecorator.new(client, connection) unless block_given?
60
+
41
61
  begin
42
62
  yield connection
43
63
  ensure
@@ -85,6 +105,8 @@ module Async
85
105
  response = request.call(connection)
86
106
 
87
107
  unless response.stream?
108
+ response.close
109
+
88
110
  raise ProtocolError, "Failed to negotiate connection: #{response.status}"
89
111
  end
90
112
 
@@ -102,7 +124,7 @@ module Async
102
124
  response = nil
103
125
  stream = nil
104
126
 
105
- connction = handler.call(framer, protocol, extensions, **@options, &block)
127
+ return handler.call(framer, protocol, extensions, **@options, &block)
106
128
  ensure
107
129
  pool.release(connection) if connection
108
130
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2023, by Samuel Williams.
5
5
 
6
6
  require 'protocol/http/request'
7
7
  require 'protocol/http/headers'
@@ -20,13 +20,14 @@ module Async
20
20
  class Wrapper
21
21
  def initialize(stream, response)
22
22
  @response = response
23
- @body = @response.body
24
23
  @stream = stream
25
24
  end
26
25
 
27
- attr_accessor :response
26
+ def close
27
+ @response.close
28
+ end
28
29
 
29
- attr_accessor :body
30
+ attr_accessor :response
30
31
  attr_accessor :stream
31
32
 
32
33
  def stream?
@@ -40,14 +41,6 @@ module Async
40
41
  def headers
41
42
  @response.headers
42
43
  end
43
-
44
- def body?
45
- true
46
- end
47
-
48
- def protocol
49
- @response.protocol
50
- end
51
44
  end
52
45
 
53
46
  class Hijack < Protocol::HTTP::Body::Readable
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2023, by Samuel Williams.
5
5
 
6
6
  require 'protocol/http/response'
7
7
  require 'async/http/body/hijack'
@@ -18,8 +18,9 @@ module Async
18
18
  if protocol
19
19
  headers.add(SEC_WEBSOCKET_PROTOCOL, protocol)
20
20
  end
21
-
21
+
22
22
  body = Async::HTTP::Body::Hijack.wrap(request, &block)
23
+
23
24
  super(request.version, 200, headers, body)
24
25
  end
25
26
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2022, by Samuel Williams.
4
+ # Copyright, 2018-2023, by Samuel Williams.
5
+ # Copyright, 2019, by Janko Marohnić.
5
6
 
6
7
  require 'protocol/websocket/connection'
7
8
  require 'protocol/websocket/headers'
@@ -30,31 +31,17 @@ module Async
30
31
  end
31
32
  end
32
33
 
33
- def initialize(framer, protocol = nil, response: nil, **options)
34
+ def initialize(framer, protocol = nil, **options)
34
35
  super(framer, **options)
35
36
 
36
37
  @protocol = protocol
37
- @response = response
38
38
  end
39
39
 
40
40
  def reusable?
41
41
  false
42
42
  end
43
43
 
44
- def close
45
- super
46
-
47
- if @response
48
- @response.finish
49
- @response = nil
50
- end
51
- end
52
-
53
44
  attr :protocol
54
-
55
- def call
56
- self.close
57
- end
58
45
  end
59
46
  end
60
47
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2023, by Samuel Williams.
5
5
 
6
6
  require 'protocol/websocket/error'
7
7
 
@@ -9,5 +9,11 @@ module Async
9
9
  module WebSocket
10
10
  class ProtocolError < ::Protocol::WebSocket::ProtocolError
11
11
  end
12
+
13
+ class Error < ::Protocol::WebSocket::Error
14
+ end
15
+
16
+ class UnsupportedVersionError < Error
17
+ end
12
18
  end
13
19
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2023, by Samuel Williams.
5
5
 
6
6
  require_relative 'connect_request'
7
7
  require_relative 'upgrade_request'
8
+ require_relative 'error'
8
9
 
9
10
  module Async
10
11
  module WebSocket
@@ -26,6 +27,10 @@ module Async
26
27
  @body = nil
27
28
  end
28
29
 
30
+ def protocol
31
+ PROTOCOL
32
+ end
33
+
29
34
  attr_accessor :scheme
30
35
  attr_accessor :authority
31
36
  attr_accessor :path
@@ -41,7 +46,7 @@ module Async
41
46
  return ConnectRequest.new(self, **@options).call(connection)
42
47
  end
43
48
 
44
- raise HTTP::Error, "Unsupported HTTP version: #{connection.version}!"
49
+ raise UnsupportedVersionError, "Unsupported HTTP version: #{connection.version}!"
45
50
  end
46
51
 
47
52
  def idempotent?
@@ -49,7 +54,8 @@ module Async
49
54
  end
50
55
 
51
56
  def to_s
52
- "\#<#{self.class} #{@scheme}://#{@authority}: #{@path}>"
57
+ uri = "#{@scheme}://#{@authority}#{@path}"
58
+ "\#<#{self.class} uri=#{uri.inspect}>"
53
59
  end
54
60
  end
55
61
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2023, by Samuel Williams.
5
5
 
6
6
  require_relative 'upgrade_response'
7
7
  require_relative 'connect_response'
@@ -19,7 +19,7 @@ module Async
19
19
  return ConnectResponse.new(request, headers, **options, &body)
20
20
  end
21
21
 
22
- raise ProtocolError, "Unsupported HTTP version: #{request.version}!"
22
+ raise UnsupportedVersionError, "Unsupported HTTP version: #{request.version}!"
23
23
  end
24
24
  end
25
25
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2022, by Samuel Williams.
4
+ # Copyright, 2018-2023, by Samuel Williams.
5
+ # Copyright, 2019, by destructobeam.
5
6
 
6
7
  require_relative 'connection'
7
8
  require_relative 'response'
@@ -13,37 +14,15 @@ module Async
13
14
  class Server < ::Protocol::HTTP::Middleware
14
15
  include ::Protocol::WebSocket::Headers
15
16
 
16
- def initialize(delegate, protocols: [], handler: Connection)
17
+ def initialize(delegate, **options, &block)
17
18
  super(delegate)
18
19
 
19
- @protocols = protocols
20
- @handler = handler
21
- end
22
-
23
- def select_protocol(request)
24
- if requested_protocol = request.headers[SEC_WEBSOCKET_PROTOCOL]
25
- return (requested_protocol & @protocols).first
26
- end
27
- end
28
-
29
- def response(request)
20
+ @options = options
21
+ @block = block
30
22
  end
31
23
 
32
24
  def call(request)
33
- if request.protocol == PROTOCOL
34
- # Select websocket sub-protocol:
35
- protocol = select_protocol(request)
36
-
37
- # request.headers = nil
38
-
39
- Response.for(request, headers, protocol: protocol, **options) do |stream|
40
- framer = Protocol::WebSocket::Framer.new(stream)
41
-
42
- yield handler.call(framer, protocol)
43
- end
44
- else
45
- super
46
- end
25
+ Async::WebSocket::Adapters::HTTP.open(request, **@options, &@block) or super
47
26
  end
48
27
  end
49
28
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2023, by Samuel Williams.
5
5
 
6
6
  require 'protocol/http/middleware'
7
7
  require 'protocol/http/request'
@@ -25,6 +25,10 @@ module Async
25
25
  @stream = nil
26
26
  end
27
27
 
28
+ def close
29
+ @response.close
30
+ end
31
+
28
32
  attr_accessor :response
29
33
 
30
34
  def stream?
@@ -39,18 +43,6 @@ module Async
39
43
  @response.headers
40
44
  end
41
45
 
42
- def body?
43
- false
44
- end
45
-
46
- def body
47
- nil
48
- end
49
-
50
- def protocol
51
- @response.protocol
52
- end
53
-
54
46
  def stream
55
47
  @stream ||= @response.hijack!
56
48
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2023, by Samuel Williams.
5
5
 
6
6
  require 'async/http/body/hijack'
7
7
  require 'protocol/http/response'
@@ -19,16 +19,17 @@ module Async
19
19
  if accept_nounce = request.headers[SEC_WEBSOCKET_KEY]&.first
20
20
  headers.add(SEC_WEBSOCKET_ACCEPT, Nounce.accept_digest(accept_nounce))
21
21
  status = 101
22
+
23
+ if protocol
24
+ headers.add(SEC_WEBSOCKET_PROTOCOL, protocol)
25
+ end
26
+
27
+ body = Async::HTTP::Body::Hijack.wrap(request, &block)
28
+
29
+ super(request.version, 101, headers, body, PROTOCOL)
22
30
  else
23
- status = 400
31
+ super(request.version, 400, headers)
24
32
  end
25
-
26
- if protocol
27
- headers.add(SEC_WEBSOCKET_PROTOCOL, protocol)
28
- end
29
-
30
- body = Async::HTTP::Body::Hijack.wrap(request, &block)
31
- super(request.version, status, headers, body, PROTOCOL)
32
33
  end
33
34
  end
34
35
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module WebSocket
8
- VERSION = "0.22.1"
8
+ VERSION = "0.23.1"
9
9
  end
10
10
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2022, by Samuel Williams.
4
+ # Copyright, 2015-2022, by Samuel Williams.
5
5
 
6
6
  require_relative 'websocket/version'
7
7
  require_relative 'websocket/server'
data/license.md CHANGED
@@ -1,10 +1,14 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2015-2022, by Samuel Williams.
3
+ Copyright, 2015-2023, by Samuel Williams.
4
+ Copyright, 2019, by Bryan Powell.
4
5
  Copyright, 2019, by destructobeam.
6
+ Copyright, 2019, by Michel Boaventura.
7
+ Copyright, 2019, by Janko Marohnić.
8
+ Copyright, 2020-2021, by Olle Jonsson.
9
+ Copyright, 2020, by Juan Antonio Martín Lucas.
5
10
  Copyright, 2021, by Gleb Sinyavskiy.
6
- Copyright, 2021, by Aurora.
7
- Copyright, 2021, by Olle Jonsson.
11
+ Copyright, 2021, by Aurora Nockert.
8
12
 
9
13
  Permission is hereby granted, free of charge, to any person obtaining a copy
10
14
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -17,27 +17,3 @@ We welcome contributions to this project.
17
17
  3. Commit your changes (`git commit -am 'Add some feature'`)
18
18
  4. Push to the branch (`git push origin my-new-feature`)
19
19
  5. Create new Pull Request
20
-
21
- ## License
22
-
23
- Released under the MIT license.
24
-
25
- Copyright, 2015, by [Samuel G. D. Williams](http://www.codeotaku.com).
26
-
27
- Permission is hereby granted, free of charge, to any person obtaining a copy
28
- of this software and associated documentation files (the "Software"), to deal
29
- in the Software without restriction, including without limitation the rights
30
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
- copies of the Software, and to permit persons to whom the Software is
32
- furnished to do so, subject to the following conditions:
33
-
34
- The above copyright notice and this permission notice shall be included in
35
- all copies or substantial portions of the Software.
36
-
37
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
43
- THE SOFTWARE.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.1
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - destructobeam
9
9
  - Olle Jonsson
10
- - Aurora
10
+ - Aurora Nockert
11
11
  - Bryan Powell
12
12
  - Gleb Sinyavskiy
13
13
  - Janko Marohnić
14
+ - Juan Antonio Martín Lucas
14
15
  - Michel Boaventura
15
- - jaml
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain:
@@ -45,7 +45,7 @@ cert_chain:
45
45
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
46
46
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
47
47
  -----END CERTIFICATE-----
48
- date: 2022-09-06 00:00:00.000000000 Z
48
+ date: 2023-02-04 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: async-http
@@ -95,14 +95,14 @@ dependencies:
95
95
  requirements:
96
96
  - - "~>"
97
97
  - !ruby/object:Gem::Version
98
- version: 0.9.1
98
+ version: '0.10'
99
99
  type: :runtime
100
100
  prerelease: false
101
101
  version_requirements: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - "~>"
104
104
  - !ruby/object:Gem::Version
105
- version: 0.9.1
105
+ version: '0.10'
106
106
  - !ruby/object:Gem::Dependency
107
107
  name: bundler
108
108
  requirement: !ruby/object:Gem::Requirement
@@ -137,14 +137,14 @@ dependencies:
137
137
  requirements:
138
138
  - - "~>"
139
139
  - !ruby/object:Gem::Version
140
- version: 0.12.0
140
+ version: 0.16.0
141
141
  type: :development
142
142
  prerelease: false
143
143
  version_requirements: !ruby/object:Gem::Requirement
144
144
  requirements:
145
145
  - - "~>"
146
146
  - !ruby/object:Gem::Version
147
- version: 0.12.0
147
+ version: 0.16.0
148
148
  - !ruby/object:Gem::Dependency
149
149
  name: sus-fixtures-async-http
150
150
  requirement: !ruby/object:Gem::Requirement
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  - !ruby/object:Gem::Version
202
202
  version: '0'
203
203
  requirements: []
204
- rubygems_version: 3.3.7
204
+ rubygems_version: 3.4.1
205
205
  signing_key:
206
206
  specification_version: 4
207
207
  summary: An async websocket library on top of websocket-driver.
metadata.gz.sig CHANGED
Binary file