async-websocket 0.22.0 → 0.23.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: 2f44102a9613ddc21a24c007f7d2dd321d86e1f7e0e9f58d9d8493ac26f65689
4
- data.tar.gz: bb7b076d16e8037c7fd6a61c7736f956c53d51088371b285e13883d3a2343445
3
+ metadata.gz: df82f3dd1772a40330282c7e81f48c7eebf4ec60b46dde2967ed205e45505183
4
+ data.tar.gz: 2a1bedaeb9fdd84c179505c14ea55cc4ab092b6084b3e9788a0ef54486cec9fa
5
5
  SHA512:
6
- metadata.gz: 1c41481ccfaeee07401f5d4607c645de83116de199908c12e921299b924763bb763d01f2181798d1c1f7f2d568474e2d3391dadc69da7ce329e441927e970519
7
- data.tar.gz: ba0006b75404a857f2b97e43e8d8bdc51db402d677975a0c1bd4e6ad20146b9e631142c65bd9cd4e14e2d2fc0e129336751eea932b89d557f3fcd1fbd68a740a
6
+ metadata.gz: d466463ab823a6d305386c27659d32f79437b59e9a12b10402d27322011241cd3b60a96051ca16c1491e3ca023d5a6810429e74deeaf4d8ec117fab2e4bb7c48
7
+ data.tar.gz: 18be04929807a7852183fa1b87dac0c4dd012ef7b86cf1f14a1ce53a3e801f86580151b584389378e7db30fde04e15a9e8f258854209c9fa265094b85413c896
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,24 +1,8 @@
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.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2023, by Samuel Williams.
5
+ # Copyright, 2021, by Aurora Nockert.
22
6
 
23
7
  require_relative '../connection'
24
8
  require_relative '../response'
@@ -49,7 +33,7 @@ module Async
49
33
  headers.add(SEC_WEBSOCKET_EXTENSIONS, header.join(";"))
50
34
  end
51
35
  end
52
-
36
+
53
37
  response = Response.for(request, headers, protocol: protocol, **options) do |stream|
54
38
  framer = Protocol::WebSocket::Framer.new(stream)
55
39
  connection = handler.call(framer, protocol, extensions)
@@ -1,27 +1,11 @@
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.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2022, by Samuel Williams.
22
5
 
23
6
  require_relative 'http'
24
7
  require 'protocol/rack/request'
8
+ require 'protocol/rack/adapter'
25
9
 
26
10
  module Async
27
11
  module WebSocket
@@ -45,4 +29,4 @@ module Async
45
29
  end
46
30
  end
47
31
  end
48
- end
32
+ end
@@ -1,24 +1,7 @@
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.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2021-2022, by Samuel Williams.
22
5
 
23
6
  require_relative 'rack'
24
7
 
@@ -1,24 +1,9 @@
1
- # frozen_string_literals: true
2
- #
3
- # Copyright, 2015, 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.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2015-2023, by Samuel Williams.
5
+ # Copyright, 2019, by Bryan Powell.
6
+ # Copyright, 2019, by Janko Marohnić.
22
7
 
23
8
  require_relative 'request'
24
9
  require_relative 'connection'
@@ -29,6 +14,8 @@ require 'protocol/http/middleware'
29
14
 
30
15
  require 'async/http/client'
31
16
 
17
+ require 'delegate'
18
+
32
19
  module Async
33
20
  module WebSocket
34
21
  # This is a basic synchronous websocket client:
@@ -48,13 +35,29 @@ module Async
48
35
  end
49
36
  end
50
37
 
38
+ class ClientCloseDecorator < SimpleDelegator
39
+ def initialize(client, connection)
40
+ @client = client
41
+ super(connection)
42
+ end
43
+
44
+ def close
45
+ super
46
+
47
+ if @client
48
+ @client.close
49
+ @client = nil
50
+ end
51
+ end
52
+ end
53
+
51
54
  # @return [Connection] an open websocket connection to the given endpoint.
52
55
  def self.connect(endpoint, *arguments, **options, &block)
53
56
  client = self.open(endpoint, *arguments)
54
57
  connection = client.connect(endpoint.authority, endpoint.path, **options)
55
-
56
- return connection unless block_given?
57
-
58
+
59
+ return ClientCloseDecorator.new(client, connection) unless block_given?
60
+
58
61
  begin
59
62
  yield connection
60
63
  ensure
@@ -102,6 +105,8 @@ module Async
102
105
  response = request.call(connection)
103
106
 
104
107
  unless response.stream?
108
+ response.close
109
+
105
110
  raise ProtocolError, "Failed to negotiate connection: #{response.status}"
106
111
  end
107
112
 
@@ -119,7 +124,7 @@ module Async
119
124
  response = nil
120
125
  stream = nil
121
126
 
122
- connction = handler.call(framer, protocol, extensions, **@options, &block)
127
+ return handler.call(framer, protocol, extensions, **@options, &block)
123
128
  ensure
124
129
  pool.release(connection) if connection
125
130
  end
@@ -1,30 +1,15 @@
1
- # frozen_string_literals: true
2
- #
3
- # Copyright, 2015, 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.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
22
5
 
23
6
  require 'protocol/http/request'
24
7
  require 'protocol/http/headers'
25
8
  require 'protocol/websocket/headers'
26
9
  require 'protocol/http/body/readable'
27
10
 
11
+ require 'async/variable'
12
+
28
13
  module Async
29
14
  module WebSocket
30
15
  # This is required for HTTP/1.x to upgrade the connection to the WebSocket protocol.
@@ -35,13 +20,14 @@ module Async
35
20
  class Wrapper
36
21
  def initialize(stream, response)
37
22
  @response = response
38
- @body = @response.body
39
23
  @stream = stream
40
24
  end
41
25
 
42
- attr_accessor :response
26
+ def close
27
+ @response.close
28
+ end
43
29
 
44
- attr_accessor :body
30
+ attr_accessor :response
45
31
  attr_accessor :stream
46
32
 
47
33
  def stream?
@@ -55,30 +41,24 @@ module Async
55
41
  def headers
56
42
  @response.headers
57
43
  end
58
-
59
- def body?
60
- true
61
- end
62
-
63
- def protocol
64
- @response.protocol
65
- end
66
44
  end
67
45
 
68
46
  class Hijack < Protocol::HTTP::Body::Readable
69
47
  def initialize(request)
70
48
  @request = request
71
- @stream = nil
49
+ @stream = Async::Variable.new
72
50
  end
73
51
 
74
52
  def stream?
75
53
  true
76
54
  end
77
55
 
78
- attr :stream
56
+ def stream
57
+ @stream.value
58
+ end
79
59
 
80
60
  def call(stream)
81
- @stream = stream
61
+ @stream.resolve(stream)
82
62
  end
83
63
  end
84
64
 
@@ -1,24 +1,7 @@
1
- # frozen_string_literals: true
2
- #
3
- # Copyright, 2015, 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.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
22
5
 
23
6
  require 'protocol/http/response'
24
7
  require 'async/http/body/hijack'
@@ -35,8 +18,9 @@ module Async
35
18
  if protocol
36
19
  headers.add(SEC_WEBSOCKET_PROTOCOL, protocol)
37
20
  end
38
-
21
+
39
22
  body = Async::HTTP::Body::Hijack.wrap(request, &block)
23
+
40
24
  super(request.version, 200, headers, body)
41
25
  end
42
26
  end
@@ -1,22 +1,8 @@
1
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
5
+ # Copyright, 2019, by Janko Marohnić.
20
6
 
21
7
  require 'protocol/websocket/connection'
22
8
  require 'protocol/websocket/headers'
@@ -45,31 +31,17 @@ module Async
45
31
  end
46
32
  end
47
33
 
48
- def initialize(framer, protocol = nil, response: nil, **options)
34
+ def initialize(framer, protocol = nil, **options)
49
35
  super(framer, **options)
50
36
 
51
37
  @protocol = protocol
52
- @response = response
53
38
  end
54
39
 
55
40
  def reusable?
56
41
  false
57
42
  end
58
43
 
59
- def close
60
- super
61
-
62
- if @response
63
- @response.finish
64
- @response = nil
65
- end
66
- end
67
-
68
44
  attr :protocol
69
-
70
- def call
71
- self.close
72
- end
73
45
  end
74
46
  end
75
47
  end
@@ -1,22 +1,7 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
20
5
 
21
6
  require 'protocol/websocket/error'
22
7
 
@@ -24,5 +9,11 @@ module Async
24
9
  module WebSocket
25
10
  class ProtocolError < ::Protocol::WebSocket::ProtocolError
26
11
  end
12
+
13
+ class Error < ::Protocol::WebSocket::Error
14
+ end
15
+
16
+ class UnsupportedVersionError < Error
17
+ end
27
18
  end
28
19
  end
@@ -1,25 +1,11 @@
1
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
20
5
 
21
6
  require_relative 'connect_request'
22
7
  require_relative 'upgrade_request'
8
+ require_relative 'error'
23
9
 
24
10
  module Async
25
11
  module WebSocket
@@ -41,6 +27,10 @@ module Async
41
27
  @body = nil
42
28
  end
43
29
 
30
+ def protocol
31
+ PROTOCOL
32
+ end
33
+
44
34
  attr_accessor :scheme
45
35
  attr_accessor :authority
46
36
  attr_accessor :path
@@ -56,7 +46,7 @@ module Async
56
46
  return ConnectRequest.new(self, **@options).call(connection)
57
47
  end
58
48
 
59
- raise HTTP::Error, "Unsupported HTTP version: #{connection.version}!"
49
+ raise UnsupportedVersionError, "Unsupported HTTP version: #{connection.version}!"
60
50
  end
61
51
 
62
52
  def idempotent?
@@ -64,7 +54,8 @@ module Async
64
54
  end
65
55
 
66
56
  def to_s
67
- "\#<#{self.class} #{@scheme}://#{@authority}: #{@path}>"
57
+ uri = "#{@scheme}://#{@authority}#{@path}"
58
+ "\#<#{self.class} uri=#{uri.inspect}>"
68
59
  end
69
60
  end
70
61
  end
@@ -1,22 +1,7 @@
1
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
20
5
 
21
6
  require_relative 'upgrade_response'
22
7
  require_relative 'connect_response'
@@ -34,7 +19,7 @@ module Async
34
19
  return ConnectResponse.new(request, headers, **options, &body)
35
20
  end
36
21
 
37
- raise ProtocolError, "Unsupported HTTP version: #{request.version}!"
22
+ raise UnsupportedVersionError, "Unsupported HTTP version: #{request.version}!"
38
23
  end
39
24
  end
40
25
  end
@@ -1,22 +1,8 @@
1
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
5
+ # Copyright, 2019, by destructobeam.
20
6
 
21
7
  require_relative 'connection'
22
8
  require_relative 'response'
@@ -28,37 +14,15 @@ module Async
28
14
  class Server < ::Protocol::HTTP::Middleware
29
15
  include ::Protocol::WebSocket::Headers
30
16
 
31
- def initialize(delegate, protocols: [], handler: Connection)
17
+ def initialize(delegate, **options, &block)
32
18
  super(delegate)
33
19
 
34
- @protocols = protocols
35
- @handler = handler
36
- end
37
-
38
- def select_protocol(request)
39
- if requested_protocol = request.headers[SEC_WEBSOCKET_PROTOCOL]
40
- return (requested_protocol & @protocols).first
41
- end
42
- end
43
-
44
- def response(request)
20
+ @options = options
21
+ @block = block
45
22
  end
46
23
 
47
24
  def call(request)
48
- if request.protocol == PROTOCOL
49
- # Select websocket sub-protocol:
50
- protocol = select_protocol(request)
51
-
52
- # request.headers = nil
53
-
54
- Response.for(request, headers, protocol: protocol, **options) do |stream|
55
- framer = Protocol::WebSocket::Framer.new(stream)
56
-
57
- yield handler.call(framer, protocol)
58
- end
59
- else
60
- super
61
- end
25
+ Async::WebSocket::Adapters::HTTP.open(request, **@options, &@block) or super
62
26
  end
63
27
  end
64
28
  end
@@ -1,24 +1,7 @@
1
- # frozen_string_literals: true
2
- #
3
- # Copyright, 2015, 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.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
22
5
 
23
6
  require 'protocol/http/middleware'
24
7
  require 'protocol/http/request'
@@ -42,6 +25,10 @@ module Async
42
25
  @stream = nil
43
26
  end
44
27
 
28
+ def close
29
+ @response.close
30
+ end
31
+
45
32
  attr_accessor :response
46
33
 
47
34
  def stream?
@@ -56,18 +43,6 @@ module Async
56
43
  @response.headers
57
44
  end
58
45
 
59
- def body?
60
- false
61
- end
62
-
63
- def body
64
- nil
65
- end
66
-
67
- def protocol
68
- @response.protocol
69
- end
70
-
71
46
  def stream
72
47
  @stream ||= @response.hijack!
73
48
  end
@@ -1,24 +1,7 @@
1
- # frozen_string_literals: true
2
- #
3
- # Copyright, 2015, 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.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
22
5
 
23
6
  require 'async/http/body/hijack'
24
7
  require 'protocol/http/response'
@@ -36,16 +19,17 @@ module Async
36
19
  if accept_nounce = request.headers[SEC_WEBSOCKET_KEY]&.first
37
20
  headers.add(SEC_WEBSOCKET_ACCEPT, Nounce.accept_digest(accept_nounce))
38
21
  status = 101
22
+
23
+ if protocol
24
+ headers.add(SEC_WEBSOCKET_PROTOCOL, protocol)
25
+ end
26
+
27
+ body = Async::HTTP::Body::Hijack.wrap(request, &block)
28
+
29
+ super(request.version, 101, headers, body, PROTOCOL)
39
30
  else
40
- status = 400
41
- end
42
-
43
- if protocol
44
- headers.add(SEC_WEBSOCKET_PROTOCOL, protocol)
31
+ super(request.version, 400, headers)
45
32
  end
46
-
47
- body = Async::HTTP::Body::Hijack.wrap(request, &block)
48
- super(request.version, status, headers, body, PROTOCOL)
49
33
  end
50
34
  end
51
35
  end
@@ -1,25 +1,10 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2022, by Samuel Williams.
20
5
 
21
6
  module Async
22
7
  module WebSocket
23
- VERSION = "0.22.0"
8
+ VERSION = "0.23.0"
24
9
  end
25
10
  end
@@ -1,22 +1,7 @@
1
- # Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2015-2022, by Samuel Williams.
20
5
 
21
6
  require_relative 'websocket/version'
22
7
  require_relative 'websocket/server'
data/license.md ADDED
@@ -0,0 +1,29 @@
1
+ # MIT License
2
+
3
+ Copyright, 2015-2023, by Samuel Williams.
4
+ Copyright, 2019, by Bryan Powell.
5
+ Copyright, 2019, by destructobeam.
6
+ Copyright, 2019, by Michel Boaventura.
7
+ Copyright, 2019, by Janko Marohnić.
8
+ Copyright, 2020-2021, by Olle Jonsson.
9
+ Copyright, 2020, by Juan Antonio Martín Lucas.
10
+ Copyright, 2021, by Gleb Sinyavskiy.
11
+ Copyright, 2021, by Aurora Nockert.
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,19 @@
1
+ # Async::WebSocket
2
+
3
+ An asynchronous websocket client/server implementation for [HTTP/1](https://tools.ietf.org/html/rfc6455) and [HTTP/2](https://tools.ietf.org/html/rfc8441).
4
+
5
+ [![Development Status](https://github.com/socketry/async-websocket/workflows/Test/badge.svg)](https://github.com/socketry/async-websocket/actions?workflow=Test)
6
+
7
+ ## Usage
8
+
9
+ Please see the [project documentation](https://socketry.github.io/async-websocket/) or serve it locally using `bake utopia:project:serve`.
10
+
11
+ ## Contributing
12
+
13
+ We welcome contributions to this project.
14
+
15
+ 1. Fork it
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create new Pull Request
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - destructobeam
9
9
  - Olle Jonsson
10
- - Aurora
10
+ - Aurora Nockert
11
11
  - Bryan Powell
12
12
  - Gleb Sinyavskiy
13
13
  - Janko Marohnić
14
+ - Juan Antonio Martín Lucas
14
15
  - Michel Boaventura
15
- - jaml
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain:
@@ -45,7 +45,7 @@ cert_chain:
45
45
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
46
46
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
47
47
  -----END CERTIFICATE-----
48
- date: 2022-08-22 00:00:00.000000000 Z
48
+ date: 2023-02-03 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: async-http
@@ -81,14 +81,14 @@ dependencies:
81
81
  requirements:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: 0.1.1
84
+ version: '0.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.1.1
91
+ version: '0.1'
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: protocol-websocket
94
94
  requirement: !ruby/object:Gem::Requirement
@@ -103,20 +103,6 @@ dependencies:
103
103
  - - "~>"
104
104
  - !ruby/object:Gem::Version
105
105
  version: 0.9.1
106
- - !ruby/object:Gem::Dependency
107
- name: async-rspec
108
- requirement: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
- type: :development
114
- prerelease: false
115
- version_requirements: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
106
  - !ruby/object:Gem::Dependency
121
107
  name: bundler
122
108
  requirement: !ruby/object:Gem::Requirement
@@ -146,47 +132,33 @@ dependencies:
146
132
  - !ruby/object:Gem::Version
147
133
  version: '0'
148
134
  - !ruby/object:Gem::Dependency
149
- name: falcon
135
+ name: sus
150
136
  requirement: !ruby/object:Gem::Requirement
151
137
  requirements:
152
138
  - - "~>"
153
139
  - !ruby/object:Gem::Version
154
- version: '0.34'
140
+ version: 0.16.0
155
141
  type: :development
156
142
  prerelease: false
157
143
  version_requirements: !ruby/object:Gem::Requirement
158
144
  requirements:
159
145
  - - "~>"
160
146
  - !ruby/object:Gem::Version
161
- version: '0.34'
162
- - !ruby/object:Gem::Dependency
163
- name: rack-test
164
- requirement: !ruby/object:Gem::Requirement
165
- requirements:
166
- - - ">="
167
- - !ruby/object:Gem::Version
168
- version: '0'
169
- type: :development
170
- prerelease: false
171
- version_requirements: !ruby/object:Gem::Requirement
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- version: '0'
147
+ version: 0.16.0
176
148
  - !ruby/object:Gem::Dependency
177
- name: rspec
149
+ name: sus-fixtures-async-http
178
150
  requirement: !ruby/object:Gem::Requirement
179
151
  requirements:
180
152
  - - "~>"
181
153
  - !ruby/object:Gem::Version
182
- version: '3.6'
154
+ version: 0.2.3
183
155
  type: :development
184
156
  prerelease: false
185
157
  version_requirements: !ruby/object:Gem::Requirement
186
158
  requirements:
187
159
  - - "~>"
188
160
  - !ruby/object:Gem::Version
189
- version: '3.6'
161
+ version: 0.2.3
190
162
  description:
191
163
  email:
192
164
  executables: []
@@ -202,13 +174,14 @@ files:
202
174
  - lib/async/websocket/connect_response.rb
203
175
  - lib/async/websocket/connection.rb
204
176
  - lib/async/websocket/error.rb
205
- - lib/async/websocket/proxy.rb
206
177
  - lib/async/websocket/request.rb
207
178
  - lib/async/websocket/response.rb
208
179
  - lib/async/websocket/server.rb
209
180
  - lib/async/websocket/upgrade_request.rb
210
181
  - lib/async/websocket/upgrade_response.rb
211
182
  - lib/async/websocket/version.rb
183
+ - license.md
184
+ - readme.md
212
185
  homepage: https://github.com/socketry/async-websocket
213
186
  licenses:
214
187
  - MIT
@@ -228,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
201
  - !ruby/object:Gem::Version
229
202
  version: '0'
230
203
  requirements: []
231
- rubygems_version: 3.3.7
204
+ rubygems_version: 3.4.1
232
205
  signing_key:
233
206
  specification_version: 4
234
207
  summary: An async websocket library on top of websocket-driver.
metadata.gz.sig CHANGED
Binary file
File without changes