websocket 1.2.9 → 1.2.11

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: 7060e7e52081f894382fcfd1d67a8f3eda15b3b0c86abf4e5dea1f44e6f1c204
4
- data.tar.gz: 93981161e7d5ded1e8182d67dd357ffc9a4c606b6bbbe6e84e7c03244db0a949
3
+ metadata.gz: 077e956ac5a77fd07eac958ff30490d55c9913d509405109a261f487b1bc9e3a
4
+ data.tar.gz: 97f424d7390fe29b8400aa039953ee604afacf76d58555f76e4c210519e880ef
5
5
  SHA512:
6
- metadata.gz: b260ffa5fac7b49981fd876ebc6adc55ced481e84fce368b8d974565edd431b9b4c563c718e889c7fd6eb28f80d8a2f20f2734d0d261610068c2f37e40c380be
7
- data.tar.gz: d3c905e52be9abe45ac1f8575b31876d7efffcebc1554a124620c6b19b7d2b4b38037a2a0c5bc2a181532af79b484ea951dfb47864aecd3c6a00686f929246d1
6
+ metadata.gz: 2b281089f46615e35500fd2b399397bcf357f1b2e418659fbe3bdb1f9b50be967a73708ccef3ef00ec32ae5cc31d8d23d8c8d3a3cdca8410cec70de7e4cac445
7
+ data.tar.gz: c8dd289b9bcb670310101eab3828e4dbd6d4cbce25744e7b66cdc52f0f4b0a8cbaf05a99bee7683f76b7c25c04c355f6008b64acae7aaf3055823099537487a4
@@ -0,0 +1,62 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - 'master'
7
+ pull_request:
8
+ branches:
9
+ - '*'
10
+
11
+ jobs:
12
+ rubocop:
13
+ runs-on: ubuntu-latest
14
+ name: Rubocop
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+
18
+ - name: Set up Ruby
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: '3.0'
22
+
23
+ - name: Install gems
24
+ run: bundle install
25
+
26
+ - name: Run Rubocop
27
+ run: bundle exec rubocop
28
+
29
+ test:
30
+ strategy:
31
+ fail-fast: false
32
+ matrix:
33
+ ruby:
34
+ - 2.1
35
+ - 2.3
36
+ - 2.4
37
+ - 2.5
38
+ - 2.6
39
+ - 2.7
40
+ - "3.0"
41
+ - 3.1
42
+ - 3.2
43
+ - 3.3
44
+ - 3.4
45
+ - jruby
46
+
47
+ runs-on: ubuntu-latest
48
+ name: Ruby ${{ matrix.ruby }}
49
+
50
+ steps:
51
+ - uses: actions/checkout@v2
52
+
53
+ - name: Set up Ruby
54
+ uses: ruby/setup-ruby@v1
55
+ with:
56
+ ruby-version: ${{ matrix.ruby }}
57
+
58
+ - name: Install gems
59
+ run: bundle install
60
+
61
+ - name: Run tests
62
+ run: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## Edge
4
+
5
+ ## 1.2.11
6
+
7
+ - remove unused base64 require that would cause issues in Ruby 3.4
8
+
9
+ ## 1.2.10
10
+
11
+ - ensure correct port is always specified for handshake
12
+ - no longer using Base64 for compatibility with Ruby 3.4+
13
+
3
14
  ## 1.2.9
4
15
 
5
16
  - avoid ruby -w warnings
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source 'http://rubygems.org'
5
5
  group :development do
6
6
  gem 'rake'
7
7
  gem 'rspec', '~> 3.7'
8
+ gem 'webrick'
8
9
 
9
10
  # Use same version as Code Climate for consistency with CI
10
11
  # https://github.com/codeclimate/codeclimate-rubocop/blob/master/Gemfile.lock
data/README.md CHANGED
@@ -4,7 +4,6 @@ Universal Ruby library to handle WebSocket protocol. It focuses on providing abs
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/websocket.svg)](http://badge.fury.io/rb/websocket)
6
6
  [![Gem Downloads](https://img.shields.io/gem/dt/websocket.svg?maxAge=2592000)](https://rubygems.org/gems/websocket)
7
- [![Travis CI](https://travis-ci.org/imanel/websocket-ruby.svg)](http://travis-ci.org/imanel/websocket-ruby)
8
7
  [![Code Climate](https://codeclimate.com/github/imanel/websocket-ruby.svg)](https://codeclimate.com/github/imanel/websocket-ruby)
9
8
 
10
9
  **Autobahn tests:** [server](http://imanel.github.com/websocket-ruby/autobahn/server/), [client](http://imanel.github.com/websocket-ruby/autobahn/client/)
@@ -118,6 +117,14 @@ WebSocket gem is written in pure Ruby, without any dependencies or native extens
118
117
 
119
118
  In order to use native extension just install [websocket-native](http://github.com/imanel/websocket-ruby-native) gem or add it to Gemfile - WebSocket will automatically detect and load it.
120
119
 
120
+ ## Support
121
+
122
+ If you like my work then consider supporting me:
123
+
124
+ [![Donate with Bitcoin](https://en.cryptobadges.io/badge/small/bc1qmxfc703ezscvd4qv0dvp7hwy7vc4kl6currs5e)](https://en.cryptobadges.io/donate/bc1qmxfc703ezscvd4qv0dvp7hwy7vc4kl6currs5e)
125
+
126
+ [![Donate with Ethereum](https://en.cryptobadges.io/badge/small/0xA7048d5F866e2c3206DC95ebFa988fF987c0BccB)](https://en.cryptobadges.io/donate/0xA7048d5F866e2c3206DC95ebFa988fF987c0BccB)
127
+
121
128
  ## License
122
129
 
123
130
  (The MIT License)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module WebSocket
4
4
  module Frame
5
- # Construct or parse incoming WebSocket Frame.
5
+ # Construct or parse outgoing WebSocket Frame.
6
6
  # @note You should NEVER use this class directly - use Client or Server subclasses instead, as they contain additional frame options(i.e. Client-side masking in draft 04)
7
7
  #
8
8
  # @example
@@ -7,7 +7,7 @@ module WebSocket
7
7
  include ExceptionHandler
8
8
  include NiceInspect
9
9
 
10
- attr_reader :host, :port, :path, :query,
10
+ attr_reader :host, :path, :query,
11
11
  :state, :version, :secure,
12
12
  :headers, :protocols
13
13
 
@@ -66,6 +66,20 @@ module WebSocket
66
66
  (@leftovers.to_s.split("\n", reserved_leftover_lines + 1)[reserved_leftover_lines] || '').strip
67
67
  end
68
68
 
69
+ # Return default port for protocol (80 for ws, 443 for wss)
70
+ def default_port
71
+ secure ? 443 : 80
72
+ end
73
+
74
+ # Check if provided port is a default one
75
+ def default_port?
76
+ port == default_port
77
+ end
78
+
79
+ def port
80
+ @port || default_port
81
+ end
82
+
69
83
  # URI of request.
70
84
  # @return [String] Full URI with protocol
71
85
  # @example
@@ -73,7 +87,7 @@ module WebSocket
73
87
  def uri
74
88
  uri = String.new(secure ? 'wss://' : 'ws://')
75
89
  uri << host
76
- uri << ":#{port}" if port
90
+ uri << ":#{port}" unless default_port?
77
91
  uri << path
78
92
  uri << "?#{query}" if query
79
93
  uri
@@ -61,7 +61,7 @@ module WebSocket
61
61
  uri = URI.parse(@url || @uri)
62
62
  @secure ||= (uri.scheme == 'wss')
63
63
  @host ||= uri.host
64
- @port ||= uri.port
64
+ @port ||= uri.port || default_port
65
65
  @path ||= uri.path
66
66
  @query ||= uri.query
67
67
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'digest/sha1'
4
- require 'base64'
5
4
 
6
5
  module WebSocket
7
6
  module Handshake
@@ -21,7 +20,7 @@ module WebSocket
21
20
  %w[Connection Upgrade]
22
21
  ]
23
22
  host = @handshake.host
24
- host += ":#{@handshake.port}" if @handshake.port
23
+ host += ":#{@handshake.port}" unless @handshake.default_port?
25
24
  keys << ['Host', host]
26
25
  keys += super
27
26
  keys << ['Sec-WebSocket-Origin', @handshake.origin] if @handshake.origin
@@ -34,13 +33,13 @@ module WebSocket
34
33
  # Sec-WebSocket-Key value
35
34
  # @return [String] key
36
35
  def key
37
- @key ||= Base64.encode64((1..16).map { rand(255).chr } * '').strip
36
+ @key ||= [(1..16).map { rand(255).chr } * ''].pack('m').strip
38
37
  end
39
38
 
40
39
  # Value of Sec-WebSocket-Accept that should be delivered back by server
41
40
  # @return [Sering] accept
42
41
  def accept
43
- @accept ||= Base64.encode64(Digest::SHA1.digest(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')).strip
42
+ @accept ||= [Digest::SHA1.digest(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')].pack('m').strip
44
43
  end
45
44
 
46
45
  # Verify if received header Sec-WebSocket-Accept matches generated one.
@@ -18,7 +18,7 @@ module WebSocket
18
18
  %w[Connection Upgrade]
19
19
  ]
20
20
  host = @handshake.host
21
- host += ":#{@handshake.port}" if @handshake.port
21
+ host += ":#{@handshake.port}" unless @handshake.default_port?
22
22
  keys << ['Host', host]
23
23
  keys << ['Origin', @handshake.origin] if @handshake.origin
24
24
  keys << ['WebSocket-Protocol', @handshake.protocols.first] if @handshake.protocols.any?
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'digest/sha1'
4
- require 'base64'
5
4
 
6
5
  module WebSocket
7
6
  module Handshake
@@ -33,7 +32,7 @@ module WebSocket
33
32
  def signature
34
33
  return unless key
35
34
  string_to_sign = "#{key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
36
- Base64.encode64(Digest::SHA1.digest(string_to_sign)).chomp
35
+ [Digest::SHA1.digest(string_to_sign)].pack('m').chomp
37
36
  end
38
37
 
39
38
  def verify_key
@@ -129,13 +129,13 @@ module WebSocket
129
129
  # Host of server according to client header
130
130
  # @return [String] host
131
131
  def host
132
- @headers['host'].to_s.split(':')[0].to_s
132
+ @host || @headers['host'].to_s.split(':')[0].to_s
133
133
  end
134
134
 
135
135
  # Port of server according to client header
136
- # @return [String] port
136
+ # @return [Integer] port
137
137
  def port
138
- @headers['host'].to_s.split(':')[1]
138
+ (@port || @headers['host'].to_s.split(':')[1] || default_port).to_i
139
139
  end
140
140
 
141
141
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebSocket
4
- VERSION = '1.2.9'.freeze
4
+ VERSION = '1.2.11'.freeze
5
5
  end
@@ -38,6 +38,10 @@ RSpec.shared_examples_for 'all client drafts' do
38
38
  expect(handshake.query).to eql('aaa=bbb')
39
39
  end
40
40
 
41
+ it 'returns default port' do
42
+ expect(handshake.port).to be(80)
43
+ end
44
+
41
45
  it 'returns valid port' do
42
46
  @request_params = { port: 123 }
43
47
  expect(handshake.port).to be(123)
@@ -47,11 +47,17 @@ RSpec.shared_examples_for 'all server drafts' do
47
47
  expect(handshake.query).to eql('aaa=bbb')
48
48
  end
49
49
 
50
+ it 'returns default port' do
51
+ handshake << client_request
52
+
53
+ expect(handshake.port).to be(80)
54
+ end
55
+
50
56
  it 'returns valid port' do
51
57
  @request_params = { port: 123 }
52
58
  handshake << client_request
53
59
 
54
- expect(handshake.port).to eql('123')
60
+ expect(handshake.port).to be(123)
55
61
  end
56
62
 
57
63
  it 'returns valid response' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.9
4
+ version: 1.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Potocki
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Universal Ruby library to handle WebSocket protocol
14
14
  email:
@@ -19,9 +19,9 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".codeclimate.yml"
21
21
  - ".github/workflows/publish.yml"
22
+ - ".github/workflows/test.yml"
22
23
  - ".gitignore"
23
24
  - ".rubocop.yml"
24
- - ".travis.yml"
25
25
  - CHANGELOG.md
26
26
  - Gemfile
27
27
  - README.md
@@ -96,7 +96,7 @@ homepage: http://github.com/imanel/websocket-ruby
96
96
  licenses:
97
97
  - MIT
98
98
  metadata: {}
99
- post_install_message:
99
+ post_install_message:
100
100
  rdoc_options: []
101
101
  require_paths:
102
102
  - lib
@@ -111,36 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
- rubygems_version: 3.0.3
115
- signing_key:
114
+ rubygems_version: 3.5.11
115
+ signing_key:
116
116
  specification_version: 4
117
117
  summary: Universal Ruby library to handle WebSocket protocol
118
- test_files:
119
- - spec/frame/incoming_03_spec.rb
120
- - spec/frame/incoming_04_spec.rb
121
- - spec/frame/incoming_05_spec.rb
122
- - spec/frame/incoming_07_spec.rb
123
- - spec/frame/incoming_75_spec.rb
124
- - spec/frame/incoming_common_spec.rb
125
- - spec/frame/masking_spec.rb
126
- - spec/frame/outgoing_03_spec.rb
127
- - spec/frame/outgoing_04_spec.rb
128
- - spec/frame/outgoing_05_spec.rb
129
- - spec/frame/outgoing_07_spec.rb
130
- - spec/frame/outgoing_75_spec.rb
131
- - spec/frame/outgoing_common_spec.rb
132
- - spec/handshake/client_04_spec.rb
133
- - spec/handshake/client_11_spec.rb
134
- - spec/handshake/client_75_spec.rb
135
- - spec/handshake/client_76_spec.rb
136
- - spec/handshake/server_04_spec.rb
137
- - spec/handshake/server_75_spec.rb
138
- - spec/handshake/server_76_spec.rb
139
- - spec/spec_helper.rb
140
- - spec/support/all_client_drafts.rb
141
- - spec/support/all_server_drafts.rb
142
- - spec/support/frames_base.rb
143
- - spec/support/handshake_requests.rb
144
- - spec/support/incoming_frames.rb
145
- - spec/support/outgoing_frames.rb
146
- - spec/support/overwrites.rb
118
+ test_files: []
data/.travis.yml DELETED
@@ -1,19 +0,0 @@
1
- dist: trusty
2
- language: ruby
3
- script: "bundle exec rake"
4
- rvm:
5
- - 2.1
6
- - 2.2
7
- - 2.3
8
- - 2.4
9
- - 2.5
10
- - ruby-head
11
- - jruby-9.1.9.0 # https://github.com/travis-ci/travis-ci/issues/8446
12
- - jruby-head
13
- - rbx-3
14
-
15
- matrix:
16
- allow_failures:
17
- - rvm: ruby-head
18
- - rvm: jruby-head
19
- - rvm: rbx-3