async-websocket 0.22.1 → 0.23.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/async/websocket/adapters/http.rb +2 -3
- data/lib/async/websocket/client.rb +27 -5
- data/lib/async/websocket/connect_request.rb +5 -12
- data/lib/async/websocket/connect_response.rb +3 -2
- data/lib/async/websocket/connection.rb +3 -16
- data/lib/async/websocket/error.rb +7 -1
- data/lib/async/websocket/request.rb +9 -3
- data/lib/async/websocket/response.rb +2 -2
- data/lib/async/websocket/server.rb +6 -27
- data/lib/async/websocket/upgrade_request.rb +5 -13
- data/lib/async/websocket/upgrade_response.rb +10 -9
- data/lib/async/websocket/version.rb +1 -1
- data/lib/async/websocket.rb +1 -1
- data/license.md +7 -3
- data/readme.md +0 -24
- data.tar.gz.sig +0 -0
- metadata +7 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df82f3dd1772a40330282c7e81f48c7eebf4ec60b46dde2967ed205e45505183
|
4
|
+
data.tar.gz: 2a1bedaeb9fdd84c179505c14ea55cc4ab092b6084b3e9788a0ef54486cec9fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d466463ab823a6d305386c27659d32f79437b59e9a12b10402d27322011241cd3b60a96051ca16c1491e3ca023d5a6810429e74deeaf4d8ec117fab2e4bb7c48
|
7
|
+
data.tar.gz: 18be04929807a7852183fa1b87dac0c4dd012ef7b86cf1f14a1ce53a3e801f86580151b584389378e7db30fde04e15a9e8f258854209c9fa265094b85413c896
|
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-
|
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,
|
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
|
-
|
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-
|
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
|
-
|
26
|
+
def close
|
27
|
+
@response.close
|
28
|
+
end
|
28
29
|
|
29
|
-
attr_accessor :
|
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-
|
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-
|
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,
|
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-
|
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-
|
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
|
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
|
-
"
|
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-
|
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
|
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-
|
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,
|
17
|
+
def initialize(delegate, **options, &block)
|
17
18
|
super(delegate)
|
18
19
|
|
19
|
-
@
|
20
|
-
@
|
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
|
-
|
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-
|
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-
|
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
|
-
|
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
|
data/lib/async/websocket.rb
CHANGED
data/license.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# MIT License
|
2
2
|
|
3
|
-
Copyright, 2015-
|
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.
|
4
|
+
version: 0.23.0
|
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:
|
48
|
+
date: 2023-02-03 00:00:00.000000000 Z
|
49
49
|
dependencies:
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: async-http
|
@@ -137,14 +137,14 @@ dependencies:
|
|
137
137
|
requirements:
|
138
138
|
- - "~>"
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
version: 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.
|
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.
|
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
|