async-websocket 0.7.0 → 0.8.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: da0bf747ee0c56a69b828547451fc478169ee13b8cf181a15af6ba5b7ab73b03
4
- data.tar.gz: 4bb105f0a98f8b4f39020aa0882745d8915b1bec7155a5fb410f3ae985d06503
3
+ metadata.gz: a501ecd90b68be17ff1a832c672ed917da9edd521d478cb0da3565f596c8f9d6
4
+ data.tar.gz: 7e3e8cb233c53198506f2ced5a2771f150248c4de916921741f0d60ea07c79e0
5
5
  SHA512:
6
- metadata.gz: 8cb039babe87b956995754dbecf8ce5b93924359b86ff5b51676fa5b9bdc1a7f0f88a85b042e04cb52d8aac900991ed3ea49eb936c6ef66760f7a7179e4d077d
7
- data.tar.gz: b6fe79b03396ff4b748436cbdaad3e5430b1890ec602c3cb1373e7a1ba04f84d4afdd625007991532aea1fa184275554e97fb4a27d1c6e70ae46c598560257c9
6
+ metadata.gz: 0b83359dd959354e0d31463065782e7b0b86a63b900930ca44252ca228366e99ac1fb69251aa605c72ae3e8ab281add7eb522f9ee01949d2c497b5500a300e77
7
+ data.tar.gz: 40912574da9db4d7bde1e8d6854ac33a35c193c0a662eed6b0426a1a5152127e7275e22279ee72f97b7fea2613acd90389b7af449a1fa4d417d2c727dfcd7d54
@@ -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: rbx-3
22
+ - rvm: truffleruby
23
+ - rvm: ruby-head
data/Gemfile CHANGED
@@ -4,6 +4,5 @@ gemspec
4
4
 
5
5
  group :test do
6
6
  gem 'rack-test'
7
- gem 'simplecov'
8
- gem 'coveralls', require: false
7
+ gem 'pry'
9
8
  end
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:test)
4
+ RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :test
6
+ task :default => :spec
@@ -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.0"
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://.", headers = {})
27
+ def initialize(socket, url = "ws://.", **options)
28
28
  @url = url
29
29
 
30
- super socket, build_client(headers)
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.each do |key, value|
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 socket, ::WebSocket::Driver.rack(self)
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
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module WebSocket
23
- VERSION = "0.7.0"
23
+ VERSION = "0.8.0"
24
24
  end
25
25
  end
@@ -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
- RSpec.describe Async::WebSocket::Connection, timeout: 5 do
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::IO::Endpoint.tcp('0.0.0.0', 9000)}
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
- require 'async/websocket/server'
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
@@ -1,28 +1,12 @@
1
1
 
2
- if ENV['COVERAGE'] || ENV['TRAVIS']
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.7.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-02-08 00:00:00.000000000 Z
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.0
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.0
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