async-websocket 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/websocket/adapters/http.rb +64 -0
- data/lib/async/websocket/adapters/rack.rb +11 -28
- data/lib/async/websocket/client.rb +8 -8
- data/lib/async/websocket/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fd37d5eb2b762f6f5d7bb8027d3d51c1a9300f63d6d38b5bd7aec5a373d1a0d
|
4
|
+
data.tar.gz: 0c8cf165cf58f920ac80534b08fef3146e08caa3676542bea72b6ae2b2fdbe9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e05aaeb2c9f4ce782bf99c57789d0e21d89a6fc262eae1141451c40c2d17776920117deae3f7c2864218a90ec5a5f7feb5ff4604460cb1cb5ee2ab783fac230d
|
7
|
+
data.tar.gz: 919c2aa1bafd05fe0e2283d201553fd546f9e734f7f4134c9adfd62ea9fb6ac714eace090d487b22fd3613dcd52d64eed6a225143a56687f9cecddea973e84db
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literals: true
|
2
|
+
#
|
3
|
+
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require_relative '../connection'
|
24
|
+
require_relative '../response'
|
25
|
+
|
26
|
+
module Async
|
27
|
+
module WebSocket
|
28
|
+
module Adapters
|
29
|
+
module HTTP
|
30
|
+
include ::Protocol::WebSocket::Headers
|
31
|
+
|
32
|
+
def self.websocket?(request)
|
33
|
+
Array(request.protocol).include?(PROTOCOL)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.open(request, headers: [], protocols: [], handler: Connection, **options, &block)
|
37
|
+
if Array(request.protocol).include?(PROTOCOL)
|
38
|
+
# Select websocket sub-protocol:
|
39
|
+
if requested_protocol = request.headers[SEC_WEBSOCKET_PROTOCOL]
|
40
|
+
protocol = (requested_protocol & protocols).first
|
41
|
+
end
|
42
|
+
|
43
|
+
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
|
+
framer = Protocol::WebSocket::Framer.new(stream)
|
48
|
+
connection = handler.call(framer, protocol)
|
49
|
+
|
50
|
+
yield connection
|
51
|
+
|
52
|
+
connection.close unless connection.closed?
|
53
|
+
end
|
54
|
+
|
55
|
+
# Once we get to this point, we no longer need to hold on to the request:
|
56
|
+
request = nil
|
57
|
+
|
58
|
+
return response
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -20,8 +20,7 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
|
-
require_relative '
|
24
|
-
require_relative '../response'
|
23
|
+
require_relative 'http'
|
25
24
|
|
26
25
|
module Async
|
27
26
|
module WebSocket
|
@@ -33,37 +32,21 @@ module Async
|
|
33
32
|
request = env['async.http.request'] and Array(request.protocol).include?(PROTOCOL)
|
34
33
|
end
|
35
34
|
|
36
|
-
def self.open(env,
|
37
|
-
if request = env['async.http.request']
|
35
|
+
def self.open(env, **options, &block)
|
36
|
+
if request = env['async.http.request']
|
38
37
|
env = nil
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
protocol = (requested_protocol & protocols).first
|
43
|
-
end
|
44
|
-
|
45
|
-
response = Response.for(request, headers, protocol: protocol, **options) do |stream|
|
46
|
-
response = nil
|
47
|
-
|
48
|
-
framer = Protocol::WebSocket::Framer.new(stream)
|
49
|
-
|
50
|
-
connection = handler.call(framer, protocol)
|
39
|
+
if response = HTTP.open(request, **options, &block)
|
40
|
+
headers = response.headers
|
51
41
|
|
52
|
-
|
42
|
+
if protocol = response.protocol
|
43
|
+
headers = Protocol::HTTP::Headers::Merged.new(headers, [
|
44
|
+
['rack.protocol', protocol]
|
45
|
+
])
|
46
|
+
end
|
53
47
|
|
54
|
-
|
48
|
+
return [response.status, headers.to_h, response.body]
|
55
49
|
end
|
56
|
-
|
57
|
-
request = nil
|
58
|
-
headers = response.headers
|
59
|
-
|
60
|
-
if protocol = response.protocol
|
61
|
-
headers = Protocol::HTTP::Headers::Merged.new(headers, [
|
62
|
-
['rack.protocol', protocol]
|
63
|
-
])
|
64
|
-
end
|
65
|
-
|
66
|
-
return [response.status, headers.to_h, response.body]
|
67
50
|
end
|
68
51
|
end
|
69
52
|
end
|
@@ -49,16 +49,16 @@ module Async
|
|
49
49
|
|
50
50
|
# @return [Connection] an open websocket connection to the given endpoint.
|
51
51
|
def self.connect(endpoint, *args, **options, &block)
|
52
|
-
self.open(endpoint, *args)
|
53
|
-
|
52
|
+
client = self.open(endpoint, *args)
|
53
|
+
connection = client.connect(endpoint.authority, endpoint.path, **options)
|
54
54
|
|
55
|
-
|
55
|
+
return connection unless block_given?
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
begin
|
58
|
+
yield connection
|
59
|
+
ensure
|
60
|
+
connection.close
|
61
|
+
client.close
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-websocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-http
|
@@ -143,6 +143,7 @@ extensions: []
|
|
143
143
|
extra_rdoc_files: []
|
144
144
|
files:
|
145
145
|
- lib/async/websocket.rb
|
146
|
+
- lib/async/websocket/adapters/http.rb
|
146
147
|
- lib/async/websocket/adapters/rack.rb
|
147
148
|
- lib/async/websocket/adapters/rails.rb
|
148
149
|
- lib/async/websocket/client.rb
|
@@ -176,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
177
|
- !ruby/object:Gem::Version
|
177
178
|
version: '0'
|
178
179
|
requirements: []
|
179
|
-
rubygems_version: 3.
|
180
|
+
rubygems_version: 3.3.0.dev
|
180
181
|
signing_key:
|
181
182
|
specification_version: 4
|
182
183
|
summary: An async websocket library on top of websocket-driver.
|