async-websocket 0.19.1 → 0.21.0

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: 0a471c482c07189921b6c9af76ea30c02e31d677897567b0616de7c818258cb5
4
- data.tar.gz: e3d34e6f906b3271ea1da568d450f46faf1e84eaed512f74ef3ba4e275a6fdbf
3
+ metadata.gz: 3f647aa6496d73f12e3fb60e2f0973f1021c0e9ed4184285114182e726644ed2
4
+ data.tar.gz: 2263444a6dea430fcf6ffe1f39a25c05a8bcdfb3e27cb54abd334b69bcadf918
5
5
  SHA512:
6
- metadata.gz: f7ad0c1cbdf9c9e4ccfe35e313474890ed9a134dacbbb1a26c584810619445db585e6fea6620390b10da44bbaa300bc4824879a8feb64505b21c1f6f35bc9d4c
7
- data.tar.gz: a27f16b8ec763fc216d4fbe63c6867289aebc25e952b68d56517c318d32504b47a2c38d791053547f0c511b512c89c017cd61fe1c1966e26d1b57904018b733c
6
+ metadata.gz: 1545f3675a0168932cfa393d24fcc68332e254c3e279e9db35c7c0478b5d541d6dd293ab0e2dfb76cc52fd5bc55c8a157ecc4e2283150ab44c814d5b791ef4eb
7
+ data.tar.gz: 3b28edd7eeef1ba6f1f89ffc05cead77f9fdcd85dc79d85d11cdafc65b85d98c4f1bed7bd9a019b71fdc0ce4ff5f1a6ab8b844844a3c75715c64987988c645d4
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
- request = env['async.http.request'] and Array(request.protocol).include?(PROTOCOL)
33
+ HTTP.websocket?(
34
+ ::Protocol::Rack::Request[env]
35
+ )
33
36
  end
34
37
 
35
38
  def self.open(env, **options, &block)
36
- if request = env['async.http.request']
37
- env = nil
38
-
39
- if response = HTTP.open(request, **options, &block)
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, *args, **options, &block)
52
- client = self.open(endpoint, *args)
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
- handler.call(framer, protocol, **@options, &block)
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,8 +23,7 @@
23
23
  require 'protocol/http/request'
24
24
  require 'protocol/http/headers'
25
25
  require 'protocol/websocket/headers'
26
-
27
- require 'async/http/body/stream'
26
+ require 'protocol/http/body/readable'
28
27
 
29
28
  module Async
30
29
  module WebSocket
@@ -66,7 +65,7 @@ module Async
66
65
  end
67
66
  end
68
67
 
69
- class Hijack < Async::HTTP::Body::Readable
68
+ class Hijack < Protocol::HTTP::Body::Readable
70
69
  def initialize(request)
71
70
  @request = request
72
71
  @stream = nil
@@ -35,7 +35,7 @@ module Async
35
35
  if protocol
36
36
  headers.add(SEC_WEBSOCKET_PROTOCOL, protocol)
37
37
  end
38
-
38
+
39
39
  body = Async::HTTP::Body::Hijack.wrap(request, &block)
40
40
  super(request.version, 200, headers, body)
41
41
  end
@@ -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
 
@@ -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 =~ /h2/i
33
+ elsif request.version =~ /http\/2/i
34
34
  return ConnectResponse.new(request, headers, **options, &body)
35
35
  end
36
36
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module WebSocket
23
- VERSION = "0.19.1"
23
+ VERSION = "0.21.0"
24
24
  end
25
25
  end
data.tar.gz.sig CHANGED
Binary file
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.19.1
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -18,33 +18,34 @@ bindir: bin
18
18
  cert_chain:
19
19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QWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
44
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
45
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
46
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
46
47
  -----END CERTIFICATE-----
47
- date: 2022-08-01 00:00:00.000000000 Z
48
+ date: 2022-08-21 00:00:00.000000000 Z
48
49
  dependencies:
49
50
  - !ruby/object:Gem::Dependency
50
51
  name: async-http
@@ -74,20 +75,34 @@ dependencies:
74
75
  - - "~>"
75
76
  - !ruby/object:Gem::Version
76
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
77
92
  - !ruby/object:Gem::Dependency
78
93
  name: protocol-websocket
79
94
  requirement: !ruby/object:Gem::Requirement
80
95
  requirements:
81
96
  - - "~>"
82
97
  - !ruby/object:Gem::Version
83
- version: 0.7.0
98
+ version: 0.8.0
84
99
  type: :runtime
85
100
  prerelease: false
86
101
  version_requirements: !ruby/object:Gem::Requirement
87
102
  requirements:
88
103
  - - "~>"
89
104
  - !ruby/object:Gem::Version
90
- version: 0.7.0
105
+ version: 0.8.0
91
106
  - !ruby/object:Gem::Dependency
92
107
  name: async-rspec
93
108
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file