async-websocket 0.17.0 → 0.19.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2b2cae182fcc4c6dbfd9724236afc25472d930a98be9496b4bc2af6f67ad502
4
- data.tar.gz: a9bb7c63e69247a287bd512973788d0e807b6464835ebef1f5d5d1c407574327
3
+ metadata.gz: 0a471c482c07189921b6c9af76ea30c02e31d677897567b0616de7c818258cb5
4
+ data.tar.gz: e3d34e6f906b3271ea1da568d450f46faf1e84eaed512f74ef3ba4e275a6fdbf
5
5
  SHA512:
6
- metadata.gz: e0f1f16a9e9fecfa3b68eec6c3b18b63588477ef3b4d2049d42a017e9f35073c6b54641585db4cbebaeff53a37537c742130354ee604620c68c79b24980d6bdf
7
- data.tar.gz: 2b43de05bcffc2089345160f21e853bba156430b183ce8b0268ca229c0903f11b723849bcec6d8117271580d9265b2ac0999aacd7be9d336987401ec09c179ba
6
+ metadata.gz: f7ad0c1cbdf9c9e4ccfe35e313474890ed9a134dacbbb1a26c584810619445db585e6fea6620390b10da44bbaa300bc4824879a8feb64505b21c1f6f35bc9d4c
7
+ data.tar.gz: a27f16b8ec763fc216d4fbe63c6867289aebc25e952b68d56517c318d32504b47a2c38d791053547f0c511b512c89c017cd61fe1c1966e26d1b57904018b733c
checksums.yaml.gz.sig ADDED
Binary file
@@ -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).any? { |e| e.casecmp?(PROTOCOL) }
34
+ end
35
+
36
+ def self.open(request, headers: [], protocols: [], handler: Connection, **options, &block)
37
+ if websocket?(request)
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 '../connection'
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, headers: [], protocols: [], handler: Connection, **options, &block)
37
- if request = env['async.http.request'] and Array(request.protocol).include?(PROTOCOL)
35
+ def self.open(env, **options, &block)
36
+ if request = env['async.http.request']
38
37
  env = nil
39
38
 
40
- # Select websocket sub-protocol:
41
- if requested_protocol = request.headers[SEC_WEBSOCKET_PROTOCOL]
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
- yield connection
42
+ if protocol = response.protocol
43
+ headers = Protocol::HTTP::Headers::Merged.new(headers, [
44
+ ['rack.protocol', protocol]
45
+ ])
46
+ end
53
47
 
54
- connection.close unless connection.closed?
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
@@ -0,0 +1,44 @@
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 'rack'
24
+
25
+ module Async
26
+ module WebSocket
27
+ module Adapters
28
+ module Rails
29
+ def self.open(request, **options, &block)
30
+ if response = Rack.open(request.env, **options, &block)
31
+ response[1]['rack.hijack'] = lambda do |stream|
32
+ response[2].call(stream)
33
+ end
34
+
35
+ # Close the response to prevent Rails from... trying to render a view?
36
+ return ::ActionDispatch::Response.new(response[0], response[1], nil).tap(&:close)
37
+ end
38
+
39
+ return ::ActionDispatch::Response.new(404, [], [])
40
+ end
41
+ end
42
+ end
43
+ end
44
+ 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) do |client|
53
- connection = client.connect(endpoint.authority, endpoint.path, **options)
52
+ client = self.open(endpoint, *args)
53
+ connection = client.connect(endpoint.authority, endpoint.path, **options)
54
54
 
55
- return connection unless block_given?
55
+ return connection unless block_given?
56
56
 
57
- begin
58
- yield connection
59
- ensure
60
- connection.close
61
- end
57
+ begin
58
+ yield connection
59
+ ensure
60
+ connection.close
61
+ client.close
62
62
  end
63
63
  end
64
64
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module WebSocket
23
- VERSION = "0.17.0"
23
+ VERSION = "0.19.1"
24
24
  end
25
25
  end
data.tar.gz.sig ADDED
@@ -0,0 +1,5 @@
1
+ ��[��ǽ�Kp��[��aALʟ0��G�G��Nt�]1��b����ק�)�tx�FV;��S�>λ�o�D� ��+�t�'��=�F��l��� q���T:������w����!8ᶔ�S�K�뺳K�P*'8Q<7�U
2
+ \�t�{t���0���#h�&��G-�n�k��
3
+ ��hص��[X�HG���
4
+ ,�z
5
+ !ʈ|�h�$�uU���6�
metadata CHANGED
@@ -1,14 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - destructobeam
9
+ - Olle Jonsson
10
+ - Aurora
11
+ - Bryan Powell
12
+ - Gleb Sinyavskiy
13
+ - Janko Marohnić
14
+ - Michel Boaventura
15
+ - jaml
8
16
  autorequire:
9
17
  bindir: bin
10
- cert_chain: []
11
- date: 2021-02-13 00:00:00.000000000 Z
18
+ cert_chain:
19
+ - |
20
+ -----BEGIN CERTIFICATE-----
21
+ MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
22
+ ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
23
+ MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
24
+ aWFtcy9EQz1vcmlvbnRyYW5zZmVyL0RDPWNvL0RDPW56MIIBojANBgkqhkiG9w0B
25
+ AQEFAAOCAY8AMIIBigKCAYEAyXLSS/cw+fXJ5e7hi+U/TeChPWeYdwJojDsFY1xr
26
+ xvtqbTTL8gbLHz5LW3QD2nfwCv3qTlw0qI3Ie7a9VMJMbSvgVEGEfQirqIgJXWMj
27
+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H9MfzxGGxTaETQYOd6b4e4Ag6
43
+ y92abGna0bmIEb4+Tx9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
44
+ RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
45
+ HiLJ8VOFx6w=
46
+ -----END CERTIFICATE-----
47
+ date: 2022-08-01 00:00:00.000000000 Z
12
48
  dependencies:
13
49
  - !ruby/object:Gem::Dependency
14
50
  name: async-http
@@ -143,7 +179,9 @@ extensions: []
143
179
  extra_rdoc_files: []
144
180
  files:
145
181
  - lib/async/websocket.rb
182
+ - lib/async/websocket/adapters/http.rb
146
183
  - lib/async/websocket/adapters/rack.rb
184
+ - lib/async/websocket/adapters/rails.rb
147
185
  - lib/async/websocket/client.rb
148
186
  - lib/async/websocket/connect_request.rb
149
187
  - lib/async/websocket/connect_response.rb
@@ -175,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
213
  - !ruby/object:Gem::Version
176
214
  version: '0'
177
215
  requirements: []
178
- rubygems_version: 3.1.2
216
+ rubygems_version: 3.3.7
179
217
  signing_key:
180
218
  specification_version: 4
181
219
  summary: An async websocket library on top of websocket-driver.
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ \�C����p�T{� ���I�g�"����o˒:��O�4ޗ�_�2X@��X�����J�[K��
2
+ �Y��lo{��T9>�?���tKJ`��m�_���/Xe�5�#՘�>J�՗�L�˦� ����"�iǝ��ʰe4�x�� ���e�T1��p����") E��H����GZ����6*���[���� P�,2�|���,��w!������E5G��h;�,[/