async-websocket 0.19.2 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/websocket/adapters/http.rb +12 -5
- data/lib/async/websocket/adapters/rack.rb +9 -16
- data/lib/async/websocket/client.rb +18 -5
- data/lib/async/websocket/connect_request.rb +2 -1
- data/lib/async/websocket/connect_response.rb +1 -1
- data/lib/async/websocket/connection.rb +7 -19
- data/lib/async/websocket/response.rb +1 -1
- data/lib/async/websocket/version.rb +1 -1
- data.tar.gz.sig +4 -3
- metadata +18 -4
- 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: 2f44102a9613ddc21a24c007f7d2dd321d86e1f7e0e9f58d9d8493ac26f65689
|
4
|
+
data.tar.gz: bb7b076d16e8037c7fd6a61c7736f956c53d51088371b285e13883d3a2343445
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c41481ccfaeee07401f5d4607c645de83116de199908c12e921299b924763bb763d01f2181798d1c1f7f2d568474e2d3391dadc69da7ce329e441927e970519
|
7
|
+
data.tar.gz: ba0006b75404a857f2b97e43e8d8bdc51db402d677975a0c1bd4e6ad20146b9e631142c65bd9cd4e14e2d2fc0e129336751eea932b89d557f3fcd1fbd68a740a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -23,6 +23,8 @@
|
|
23
23
|
require_relative '../connection'
|
24
24
|
require_relative '../response'
|
25
25
|
|
26
|
+
require 'protocol/websocket/extensions'
|
27
|
+
|
26
28
|
module Async
|
27
29
|
module WebSocket
|
28
30
|
module Adapters
|
@@ -33,19 +35,24 @@ module Async
|
|
33
35
|
Array(request.protocol).any? { |e| e.casecmp?(PROTOCOL) }
|
34
36
|
end
|
35
37
|
|
36
|
-
def self.open(request, headers: [], protocols: [], handler: Connection, **options, &block)
|
38
|
+
def self.open(request, headers: [], protocols: [], handler: Connection, extensions: ::Protocol::WebSocket::Extensions::Server.default, **options, &block)
|
37
39
|
if websocket?(request)
|
40
|
+
headers = Protocol::HTTP::Headers[headers]
|
41
|
+
|
38
42
|
# Select websocket sub-protocol:
|
39
43
|
if requested_protocol = request.headers[SEC_WEBSOCKET_PROTOCOL]
|
40
44
|
protocol = (requested_protocol & protocols).first
|
41
45
|
end
|
42
46
|
|
47
|
+
if extensions and extension_headers = request.headers[SEC_WEBSOCKET_EXTENSIONS]
|
48
|
+
extensions.accept(extension_headers) do |header|
|
49
|
+
headers.add(SEC_WEBSOCKET_EXTENSIONS, header.join(";"))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
43
53
|
response = Response.for(request, headers, protocol: protocol, **options) do |stream|
|
44
|
-
# Once we get to this point, we no longer need to hold on to the response:
|
45
|
-
response = nil
|
46
|
-
|
47
54
|
framer = Protocol::WebSocket::Framer.new(stream)
|
48
|
-
connection = handler.call(framer, protocol)
|
55
|
+
connection = handler.call(framer, protocol, extensions)
|
49
56
|
|
50
57
|
yield connection
|
51
58
|
|
@@ -21,6 +21,7 @@
|
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
23
|
require_relative 'http'
|
24
|
+
require 'protocol/rack/request'
|
24
25
|
|
25
26
|
module Async
|
26
27
|
module WebSocket
|
@@ -29,27 +30,19 @@ module Async
|
|
29
30
|
include ::Protocol::WebSocket::Headers
|
30
31
|
|
31
32
|
def self.websocket?(env)
|
32
|
-
|
33
|
+
HTTP.websocket?(
|
34
|
+
::Protocol::Rack::Request[env]
|
35
|
+
)
|
33
36
|
end
|
34
37
|
|
35
38
|
def self.open(env, **options, &block)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
headers = response.headers
|
41
|
-
|
42
|
-
if protocol = response.protocol
|
43
|
-
headers = Protocol::HTTP::Headers::Merged.new(headers, [
|
44
|
-
['rack.protocol', protocol]
|
45
|
-
])
|
46
|
-
end
|
47
|
-
|
48
|
-
return [response.status, headers.to_h, response.body]
|
49
|
-
end
|
39
|
+
request = ::Protocol::Rack::Request[env]
|
40
|
+
|
41
|
+
if response = HTTP.open(request, **options, &block)
|
42
|
+
return Protocol::Rack::Adapter.make_response(env, response)
|
50
43
|
end
|
51
44
|
end
|
52
45
|
end
|
53
46
|
end
|
54
47
|
end
|
55
|
-
end
|
48
|
+
end
|
@@ -24,6 +24,7 @@ require_relative 'request'
|
|
24
24
|
require_relative 'connection'
|
25
25
|
|
26
26
|
require 'protocol/websocket/headers'
|
27
|
+
require 'protocol/websocket/extensions'
|
27
28
|
require 'protocol/http/middleware'
|
28
29
|
|
29
30
|
require 'async/http/client'
|
@@ -48,8 +49,8 @@ module Async
|
|
48
49
|
end
|
49
50
|
|
50
51
|
# @return [Connection] an open websocket connection to the given endpoint.
|
51
|
-
def self.connect(endpoint, *
|
52
|
-
client = self.open(endpoint, *
|
52
|
+
def self.connect(endpoint, *arguments, **options, &block)
|
53
|
+
client = self.open(endpoint, *arguments)
|
53
54
|
connection = client.connect(endpoint.authority, endpoint.path, **options)
|
54
55
|
|
55
56
|
return connection unless block_given?
|
@@ -86,8 +87,13 @@ module Async
|
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
89
|
-
def connect(authority, path, headers: nil, handler: Connection, **options, &block)
|
90
|
+
def connect(authority, path, headers: nil, handler: Connection, extensions: ::Protocol::WebSocket::Extensions::Client.default, **options, &block)
|
90
91
|
headers = ::Protocol::HTTP::Headers[headers]
|
92
|
+
|
93
|
+
extensions&.offer do |extension|
|
94
|
+
headers.add(SEC_WEBSOCKET_EXTENSIONS, extension.join("; "))
|
95
|
+
end
|
96
|
+
|
91
97
|
request = Request.new(nil, authority, path, headers, **options)
|
92
98
|
|
93
99
|
pool = @delegate.pool
|
@@ -101,12 +107,19 @@ module Async
|
|
101
107
|
|
102
108
|
protocol = response.headers[SEC_WEBSOCKET_PROTOCOL]&.first
|
103
109
|
stream = response.stream
|
104
|
-
response = nil
|
105
110
|
|
106
111
|
framer = Framer.new(pool, connection, stream)
|
112
|
+
|
107
113
|
connection = nil
|
108
114
|
|
109
|
-
|
115
|
+
if extension_headers = response.headers[SEC_WEBSOCKET_EXTENSIONS]
|
116
|
+
extensions.accept(extension_headers)
|
117
|
+
end
|
118
|
+
|
119
|
+
response = nil
|
120
|
+
stream = nil
|
121
|
+
|
122
|
+
connction = handler.call(framer, protocol, extensions, **@options, &block)
|
110
123
|
ensure
|
111
124
|
pool.release(connection) if connection
|
112
125
|
end
|
@@ -23,6 +23,7 @@
|
|
23
23
|
require 'protocol/http/request'
|
24
24
|
require 'protocol/http/headers'
|
25
25
|
require 'protocol/websocket/headers'
|
26
|
+
require 'protocol/http/body/readable'
|
26
27
|
|
27
28
|
module Async
|
28
29
|
module WebSocket
|
@@ -64,7 +65,7 @@ module Async
|
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
67
|
-
class Hijack <
|
68
|
+
class Hijack < Protocol::HTTP::Body::Readable
|
68
69
|
def initialize(request)
|
69
70
|
@request = request
|
70
71
|
@stream = nil
|
@@ -31,9 +31,11 @@ module Async
|
|
31
31
|
class Connection < ::Protocol::WebSocket::Connection
|
32
32
|
include ::Protocol::WebSocket::Headers
|
33
33
|
|
34
|
-
def self.call(framer, protocol = [], **options)
|
34
|
+
def self.call(framer, protocol = [], extensions = nil, **options)
|
35
35
|
instance = self.new(framer, Array(protocol).first, **options)
|
36
36
|
|
37
|
+
extensions&.apply(instance)
|
38
|
+
|
37
39
|
return instance unless block_given?
|
38
40
|
|
39
41
|
begin
|
@@ -50,6 +52,10 @@ module Async
|
|
50
52
|
@response = response
|
51
53
|
end
|
52
54
|
|
55
|
+
def reusable?
|
56
|
+
false
|
57
|
+
end
|
58
|
+
|
53
59
|
def close
|
54
60
|
super
|
55
61
|
|
@@ -61,24 +67,6 @@ module Async
|
|
61
67
|
|
62
68
|
attr :protocol
|
63
69
|
|
64
|
-
def read
|
65
|
-
if buffer = super
|
66
|
-
parse(buffer)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def write(object)
|
71
|
-
super(dump(object))
|
72
|
-
end
|
73
|
-
|
74
|
-
def parse(buffer)
|
75
|
-
JSON.parse(buffer, symbolize_names: true)
|
76
|
-
end
|
77
|
-
|
78
|
-
def dump(object)
|
79
|
-
JSON.dump(object)
|
80
|
-
end
|
81
|
-
|
82
70
|
def call
|
83
71
|
self.close
|
84
72
|
end
|
@@ -30,7 +30,7 @@ module Async
|
|
30
30
|
def self.for(request, headers = nil, **options, &body)
|
31
31
|
if request.version =~ /http\/1/i
|
32
32
|
return UpgradeResponse.new(request, headers, **options, &body)
|
33
|
-
elsif request.version =~ /
|
33
|
+
elsif request.version =~ /http\/2/i
|
34
34
|
return ConnectResponse.new(request, headers, **options, &body)
|
35
35
|
end
|
36
36
|
|
data.tar.gz.sig
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
.�-�՝�G�}L���..���0'�@V��%�:s���M1
|
2
|
+
�)*w
|
3
|
+
Ba���a���._`�x�����ݫQ��K��>g��<�A�F)=ǚE�%��� k?�dҞr<�Hľ>�A�|ߔ{�� �D��פV��8�Ձany��x��Sv:�`���帽���%�ƃe��<�����Cs�YY����ZP_�3�����~Q�@��s�X�X��a�B�[ō�I�_ꗯ�l�w|���#Y ����%����T(T[?p#�i�ۜ�!0�q@���
|
4
|
+
��괯�"�jO�lb����C� �m��w��RmW|$�WCn/l�ǝ��sn��oP��{��3������[�=<R�
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-websocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -45,7 +45,7 @@ cert_chain:
|
|
45
45
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
46
46
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
47
47
|
-----END CERTIFICATE-----
|
48
|
-
date: 2022-08-
|
48
|
+
date: 2022-08-22 00:00:00.000000000 Z
|
49
49
|
dependencies:
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: async-http
|
@@ -75,20 +75,34 @@ dependencies:
|
|
75
75
|
- - "~>"
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '1.23'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: protocol-rack
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.1.1
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 0.1.1
|
78
92
|
- !ruby/object:Gem::Dependency
|
79
93
|
name: protocol-websocket
|
80
94
|
requirement: !ruby/object:Gem::Requirement
|
81
95
|
requirements:
|
82
96
|
- - "~>"
|
83
97
|
- !ruby/object:Gem::Version
|
84
|
-
version: 0.
|
98
|
+
version: 0.9.1
|
85
99
|
type: :runtime
|
86
100
|
prerelease: false
|
87
101
|
version_requirements: !ruby/object:Gem::Requirement
|
88
102
|
requirements:
|
89
103
|
- - "~>"
|
90
104
|
- !ruby/object:Gem::Version
|
91
|
-
version: 0.
|
105
|
+
version: 0.9.1
|
92
106
|
- !ruby/object:Gem::Dependency
|
93
107
|
name: async-rspec
|
94
108
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
Binary file
|