async-websocket 0.20.0 → 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: 0a051f2295a5f0874fb78259a546cf65e99a7b507a781df04817d9472391506c
4
- data.tar.gz: 7fdd299047a497220c5ef7640a287b6f52691982ff12175f8d93f9a258de814e
3
+ metadata.gz: 3f647aa6496d73f12e3fb60e2f0973f1021c0e9ed4184285114182e726644ed2
4
+ data.tar.gz: 2263444a6dea430fcf6ffe1f39a25c05a8bcdfb3e27cb54abd334b69bcadf918
5
5
  SHA512:
6
- metadata.gz: 6fb7a9e49527d946cc762da5a45bb389c91debdc55598b959dd4543f1f31e5921d3fd3901d2b99d9d7d366b3cb7cb3efde014122cce4e6fb981a372a852a5db5
7
- data.tar.gz: a6f33b3043a6453754f429ac494f4afb1e44f2e7bc6511ab3d42c65e55a3e59efcc5e8d99f807d68fe707a1f1b1084a2aaaade0393d3d7b6c7dad4396b866afd
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
 
@@ -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
@@ -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
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module WebSocket
23
- VERSION = "0.20.0"
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.20.0
4
+ version: 0.21.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-19 00:00:00.000000000 Z
48
+ date: 2022-08-21 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: async-http
@@ -76,33 +76,33 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '1.23'
78
78
  - !ruby/object:Gem::Dependency
79
- name: protocol-websocket
79
+ name: protocol-rack
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: 0.7.0
84
+ version: 0.1.1
85
85
  type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
- version: 0.7.0
91
+ version: 0.1.1
92
92
  - !ruby/object:Gem::Dependency
93
- name: protocol-rack
93
+ name: protocol-websocket
94
94
  requirement: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - "~>"
97
97
  - !ruby/object:Gem::Version
98
- version: 0.1.1
98
+ version: 0.8.0
99
99
  type: :runtime
100
100
  prerelease: false
101
101
  version_requirements: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - "~>"
104
104
  - !ruby/object:Gem::Version
105
- version: 0.1.1
105
+ version: 0.8.0
106
106
  - !ruby/object:Gem::Dependency
107
107
  name: async-rspec
108
108
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file