async-websocket 0.7.0 → 0.8.0
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 +4 -4
- data/.travis.yml +6 -3
- data/Gemfile +1 -2
- data/Rakefile +2 -2
- data/async-websocket.gemspec +2 -1
- data/lib/async/websocket/client.rb +5 -5
- data/lib/async/websocket/server.rb +5 -5
- data/lib/async/websocket/version.rb +1 -1
- data/spec/async/websocket/client_spec.rb +21 -1
- data/spec/async/websocket/connection_spec.rb +24 -2
- data/spec/async/websocket/connection_spec.ru +20 -21
- data/spec/async/websocket/upgrade.rb +41 -0
- data/spec/spec_helper.rb +3 -19
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a501ecd90b68be17ff1a832c672ed917da9edd521d478cb0da3565f596c8f9d6
|
4
|
+
data.tar.gz: 7e3e8cb233c53198506f2ced5a2771f150248c4de916921741f0d60ea07c79e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b83359dd959354e0d31463065782e7b0b86a63b900930ca44252ca228366e99ac1fb69251aa605c72ae3e8ab281add7eb522f9ee01949d2c497b5500a300e77
|
7
|
+
data.tar.gz: 40912574da9db4d7bde1e8d6854ac33a35c193c0a662eed6b0426a1a5152127e7275e22279ee72f97b7fea2613acd90389b7af449a1fa4d417d2c727dfcd7d54
|
data/.travis.yml
CHANGED
@@ -10,11 +10,14 @@ matrix:
|
|
10
10
|
- rvm: 2.3
|
11
11
|
- rvm: 2.4
|
12
12
|
- rvm: 2.5
|
13
|
+
- rvm: 2.6
|
14
|
+
- rvm: 2.6
|
15
|
+
env: COVERAGE=BriefSummary,Coveralls
|
13
16
|
- rvm: jruby-head
|
14
17
|
env: JRUBY_OPTS="--debug -X+O"
|
18
|
+
- rvm: truffleruby
|
15
19
|
- rvm: ruby-head
|
16
|
-
- rvm: rbx-3
|
17
20
|
allow_failures:
|
18
|
-
- rvm: ruby-head
|
19
21
|
- rvm: jruby-head
|
20
|
-
- rvm:
|
22
|
+
- rvm: truffleruby
|
23
|
+
- rvm: ruby-head
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/async-websocket.gemspec
CHANGED
@@ -20,8 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_dependency "async-io"
|
21
21
|
|
22
22
|
spec.add_development_dependency "async-rspec"
|
23
|
-
spec.add_development_dependency "falcon", "~> 0.17
|
23
|
+
spec.add_development_dependency "falcon", "~> 0.17"
|
24
24
|
|
25
|
+
spec.add_development_dependency "covered"
|
25
26
|
spec.add_development_dependency "bundler"
|
26
27
|
spec.add_development_dependency "rspec", "~> 3.6"
|
27
28
|
spec.add_development_dependency "rake"
|
@@ -24,15 +24,15 @@ module Async
|
|
24
24
|
module WebSocket
|
25
25
|
# This is a basic synchronous websocket client:
|
26
26
|
class Client < Connection
|
27
|
-
def initialize(socket, url = "ws://.",
|
27
|
+
def initialize(socket, url = "ws://.", **options)
|
28
28
|
@url = url
|
29
29
|
|
30
|
-
super socket, build_client(
|
30
|
+
super socket, build_client(**options)
|
31
31
|
end
|
32
32
|
|
33
|
-
def build_client(headers)
|
34
|
-
::WebSocket::Driver.client(self).tap do |client|
|
35
|
-
headers
|
33
|
+
def build_client(headers: nil, **options)
|
34
|
+
::WebSocket::Driver.client(self, options).tap do |client|
|
35
|
+
headers&.each do |key, value|
|
36
36
|
client.set_header(key, value)
|
37
37
|
end
|
38
38
|
end
|
@@ -23,13 +23,13 @@ require_relative 'connection'
|
|
23
23
|
module Async
|
24
24
|
module WebSocket
|
25
25
|
class Server < Connection
|
26
|
-
def initialize(env, socket)
|
26
|
+
def initialize(env, socket, **options)
|
27
27
|
scheme = env['rack.url_scheme'] == 'https' ? 'wss' : 'ws'
|
28
|
-
@url = "#{scheme}://#{env['HTTP_HOST']}#{env['REQUEST_URI']}"
|
29
28
|
|
29
|
+
@url = "#{scheme}://#{env['HTTP_HOST']}#{env['REQUEST_URI']}"
|
30
30
|
@env = env
|
31
31
|
|
32
|
-
super
|
32
|
+
super(socket, ::WebSocket::Driver.rack(self, options))
|
33
33
|
end
|
34
34
|
|
35
35
|
attr :env
|
@@ -37,7 +37,7 @@ module Async
|
|
37
37
|
|
38
38
|
HIJACK_RESPONSE = [-1, {}, []].freeze
|
39
39
|
|
40
|
-
def self.open(env)
|
40
|
+
def self.open(env, **options)
|
41
41
|
if ::WebSocket::Driver.websocket?(env)
|
42
42
|
return nil unless env['rack.hijack?']
|
43
43
|
|
@@ -46,7 +46,7 @@ module Async
|
|
46
46
|
env['rack.hijack'].call
|
47
47
|
)
|
48
48
|
|
49
|
-
connection = self.new(env, peer)
|
49
|
+
connection = self.new(env, peer, options)
|
50
50
|
|
51
51
|
return connection unless block_given?
|
52
52
|
|
@@ -1,3 +1,23 @@
|
|
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.
|
20
|
+
|
1
21
|
require "async/websocket/client"
|
2
22
|
|
3
23
|
RSpec.describe Async::WebSocket::Client do
|
@@ -19,7 +39,7 @@ RSpec.describe Async::WebSocket::Client do
|
|
19
39
|
expect(client_double).to receive(:set_header).with(key, value)
|
20
40
|
end
|
21
41
|
|
22
|
-
described_class.new(double(write: nil), "", headers)
|
42
|
+
described_class.new(double(write: nil), "", headers: headers)
|
23
43
|
end
|
24
44
|
|
25
45
|
context "without passing headers" do
|
@@ -24,11 +24,14 @@ require 'async/websocket/client'
|
|
24
24
|
require 'rack/test'
|
25
25
|
require 'falcon/server'
|
26
26
|
require 'falcon/adapters/rack'
|
27
|
+
require 'async/http/url_endpoint'
|
27
28
|
|
28
|
-
|
29
|
+
require 'pry'
|
30
|
+
|
31
|
+
RSpec.describe Async::WebSocket::Connection, timeout: nil do
|
29
32
|
include_context Async::RSpec::Reactor
|
30
33
|
|
31
|
-
let(:server_address) {Async::
|
34
|
+
let(:server_address) {Async::HTTP::URLEndpoint.parse("http://localhost:9000")}
|
32
35
|
let(:app) {Rack::Builder.parse_file(File.expand_path('../connection_spec.ru', __FILE__)).first}
|
33
36
|
let(:server) {Falcon::Server.new(Falcon::Server.middleware(app, verbose: true), server_address)}
|
34
37
|
|
@@ -53,4 +56,23 @@ RSpec.describe Async::WebSocket::Connection, timeout: 5 do
|
|
53
56
|
|
54
57
|
server_task.stop
|
55
58
|
end
|
59
|
+
|
60
|
+
it "should send back Sec-WebSocket-Protocol header" do
|
61
|
+
server_task = reactor.async do
|
62
|
+
server.run
|
63
|
+
end
|
64
|
+
|
65
|
+
# Should send and receive Sec-WebSocket-Protocol header as
|
66
|
+
# `ws`
|
67
|
+
|
68
|
+
server_address.connect do |socket|
|
69
|
+
client = Async::WebSocket::Client.new(socket, protocols: ['ws'])
|
70
|
+
|
71
|
+
expect(client.next_event).to be_kind_of(WebSocket::Driver::OpenEvent)
|
72
|
+
|
73
|
+
expect(client.driver.protocol).to be == 'ws'
|
74
|
+
end
|
75
|
+
|
76
|
+
server_task.stop
|
77
|
+
end
|
56
78
|
end
|
@@ -1,25 +1,24 @@
|
|
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
20
|
|
2
|
-
|
3
|
-
|
4
|
-
class Upgrade
|
5
|
-
def initialize(app)
|
6
|
-
@app = app
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(env)
|
10
|
-
result = Async::WebSocket::Server.open(env) do |server|
|
11
|
-
read, write = IO.pipe
|
12
|
-
|
13
|
-
Process.spawn("ls -lah", :out => write)
|
14
|
-
write.close
|
15
|
-
|
16
|
-
read.each_line do |line|
|
17
|
-
server.send_text(line)
|
18
|
-
end
|
19
|
-
|
20
|
-
end or @app.call(env)
|
21
|
-
end
|
22
|
-
end
|
21
|
+
require_relative 'upgrade'
|
23
22
|
|
24
23
|
use Upgrade
|
25
24
|
|
@@ -0,0 +1,41 @@
|
|
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.
|
20
|
+
|
21
|
+
require 'async/websocket/server'
|
22
|
+
|
23
|
+
class Upgrade
|
24
|
+
def initialize(app)
|
25
|
+
@app = app
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(env)
|
29
|
+
result = Async::WebSocket::Server.open(env, protocols: ['ws']) do |server|
|
30
|
+
read, write = IO.pipe
|
31
|
+
|
32
|
+
Process.spawn("ls -lah", :out => write)
|
33
|
+
write.close
|
34
|
+
|
35
|
+
read.each_line do |line|
|
36
|
+
server.send_text(line)
|
37
|
+
end
|
38
|
+
|
39
|
+
end or @app.call(env)
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,28 +1,12 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'simplecov'
|
5
|
-
|
6
|
-
SimpleCov.start do
|
7
|
-
add_filter "/spec/"
|
8
|
-
end
|
9
|
-
|
10
|
-
if ENV['TRAVIS']
|
11
|
-
require 'coveralls'
|
12
|
-
Coveralls.wear!
|
13
|
-
end
|
14
|
-
rescue LoadError
|
15
|
-
warn "Could not load simplecov: #{$!}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
require "bundler/setup"
|
20
|
-
require "async/websocket"
|
2
|
+
require 'covered/rspec'
|
21
3
|
|
22
4
|
# Shared rspec helpers:
|
23
5
|
require "async/rspec"
|
24
6
|
|
25
7
|
RSpec.configure do |config|
|
8
|
+
config.disable_monkey_patching!
|
9
|
+
|
26
10
|
# Enable flags like --only-failures and --next-failure
|
27
11
|
config.example_status_persistence_file_path = ".rspec_status"
|
28
12
|
|
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.8.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: 2019-
|
11
|
+
date: 2019-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-driver
|
@@ -58,14 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.17
|
61
|
+
version: '0.17'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.17
|
68
|
+
version: '0.17'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: covered
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,6 +183,7 @@ files:
|
|
169
183
|
- spec/async/websocket/client_spec.rb
|
170
184
|
- spec/async/websocket/connection_spec.rb
|
171
185
|
- spec/async/websocket/connection_spec.ru
|
186
|
+
- spec/async/websocket/upgrade.rb
|
172
187
|
- spec/spec_helper.rb
|
173
188
|
homepage: ''
|
174
189
|
licenses:
|
@@ -197,4 +212,5 @@ test_files:
|
|
197
212
|
- spec/async/websocket/client_spec.rb
|
198
213
|
- spec/async/websocket/connection_spec.rb
|
199
214
|
- spec/async/websocket/connection_spec.ru
|
215
|
+
- spec/async/websocket/upgrade.rb
|
200
216
|
- spec/spec_helper.rb
|