websocket 1.2.8 → 1.2.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc36fa232460616657d774b6ae0d21bac79c8123730812ac1032d185a4fa090a
4
- data.tar.gz: 125432097dd592f40606fd4e2d7fb30f1b029b794b832eda0d2f0e9f4b1d824a
3
+ metadata.gz: 4463e6e6f36b66267381b20c6dbab2fc1fd417319fcc9d2fb1a760c87a7d26e6
4
+ data.tar.gz: 71187172f0f75a938c50573cf0b2b378f092ec93f42b57cacea5c73f559ba085
5
5
  SHA512:
6
- metadata.gz: 825c8e711023468f699cf0cf0a0f9e1ce462a81bc2ca5ea1a1523b079548bd21d9ac9bc0938d47d154a3e4706c23ff71e9abd93612ec9e83f3b1063651e7e7bb
7
- data.tar.gz: 66a68866a9c231658d7cdd203250a4c1cab1d860b4fe2523343d77fd7969f48fc86471cc0920795fe52499ee3aa93825294a1651ab6968ca76839ee2ec34d200
6
+ metadata.gz: 9875cb5996d580b1564e4a6cf2ef897ccf99d37577d2a22dd1e7750323dfc5aad181641411596b96667ebf614604d0ff581e3b39ae75d49c2bc1290c1ec4a82d
7
+ data.tar.gz: fd772c288aee75ca9c7328fd8096bc30bde61a69247633a4b9a2a7e61dff260d48bd4abbf957a02ead55ac83c365d945f3753b053c9e6f5cf237925b2c510a06
@@ -0,0 +1,17 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - v*
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Release Gem
14
+ uses: cadwallion/publish-rubygems-action@master
15
+ env:
16
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
@@ -0,0 +1,61 @@
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
+ - jruby
45
+
46
+ runs-on: ubuntu-latest
47
+ name: Ruby ${{ matrix.ruby }}
48
+
49
+ steps:
50
+ - uses: actions/checkout@v2
51
+
52
+ - name: Set up Ruby
53
+ uses: ruby/setup-ruby@v1
54
+ with:
55
+ ruby-version: ${{ matrix.ruby }}
56
+
57
+ - name: Install gems
58
+ run: bundle install
59
+
60
+ - name: Run tests
61
+ run: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## Edge
4
+
5
+ ## 1.2.10
6
+
7
+ - ensure correct port is always specified for handshake
8
+ - no longer using Base64 for compatibility with Ruby 3.4+
9
+
10
+ ## 1.2.9
11
+
12
+ - avoid ruby -w warnings
13
+
3
14
  ## 1.2.8
4
15
 
5
16
  - restore support for Ruby 2.0+
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)
@@ -14,7 +14,7 @@ module WebSocket
14
14
  # @param [String] method_name Name of method that should be wrapped and rescued
15
15
  # @param [Hash] options Options for rescue
16
16
  #
17
- # @options options [Any] :return Value that should be returned instead of raised error
17
+ # @option options [Any] :return Value that should be returned instead of raised error
18
18
  def rescue_method(method_name, options = {})
19
19
  define_method "#{method_name}_with_rescue" do |*args|
20
20
  begin
@@ -5,6 +5,7 @@ module WebSocket
5
5
  class Data < String
6
6
  def initialize(*args)
7
7
  super(*convert_args(args))
8
+ @masking_key = nil
8
9
  end
9
10
 
10
11
  def <<(*args)
@@ -20,6 +20,11 @@ module WebSocket
20
20
  # Hash of frame opcodes and it's names
21
21
  FRAME_TYPES_INVERSE = FRAME_TYPES.invert.freeze
22
22
 
23
+ def initialize(frame)
24
+ super
25
+ @application_data_buffer = nil
26
+ end
27
+
23
28
  # @see WebSocket::Frame::Base#supported_frames
24
29
  def supported_frames
25
30
  %i[text binary close ping pong]
@@ -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
@@ -21,7 +21,7 @@ module WebSocket
21
21
  %w[Connection Upgrade]
22
22
  ]
23
23
  host = @handshake.host
24
- host += ":#{@handshake.port}" if @handshake.port
24
+ host += ":#{@handshake.port}" unless @handshake.default_port?
25
25
  keys << ['Host', host]
26
26
  keys += super
27
27
  keys << ['Sec-WebSocket-Origin', @handshake.origin] if @handshake.origin
@@ -34,13 +34,13 @@ module WebSocket
34
34
  # Sec-WebSocket-Key value
35
35
  # @return [String] key
36
36
  def key
37
- @key ||= Base64.encode64((1..16).map { rand(255).chr } * '').strip
37
+ @key ||= [(1..16).map { rand(255).chr } * ''].pack('m').strip
38
38
  end
39
39
 
40
40
  # Value of Sec-WebSocket-Accept that should be delivered back by server
41
41
  # @return [Sering] accept
42
42
  def accept
43
- @accept ||= Base64.encode64(Digest::SHA1.digest(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')).strip
43
+ @accept ||= [Digest::SHA1.digest(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11')].pack('m').strip
44
44
  end
45
45
 
46
46
  # 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?
@@ -71,7 +71,7 @@ module WebSocket
71
71
  NOISE_CHARS = ("\x21".."\x2f").to_a + ("\x3a".."\x7e").to_a
72
72
 
73
73
  # Generate Sec-WebSocket-Key1 and Sec-WebSocket-Key2
74
- # @param [String] name of key. Will be used to set number variable needed later. Valid values: key1, key2
74
+ # @param key [String] name of key. Will be used to set number variable needed later. Valid values: key1, key2
75
75
  # @return [String] generated key
76
76
  def generate_key(key)
77
77
  spaces = rand(1..12)
@@ -33,7 +33,7 @@ module WebSocket
33
33
  def signature
34
34
  return unless key
35
35
  string_to_sign = "#{key}258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
36
- Base64.encode64(Digest::SHA1.digest(string_to_sign)).chomp
36
+ [Digest::SHA1.digest(string_to_sign)].pack('m').chomp
37
37
  end
38
38
 
39
39
  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.8'.freeze
4
+ VERSION = '1.2.10'.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.8
4
+ version: 1.2.10
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: 2018-05-25 00:00:00.000000000 Z
11
+ date: 2023-09-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Universal Ruby library to handle WebSocket protocol
14
14
  email:
@@ -18,9 +18,10 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - ".codeclimate.yml"
21
+ - ".github/workflows/publish.yml"
22
+ - ".github/workflows/test.yml"
21
23
  - ".gitignore"
22
24
  - ".rubocop.yml"
23
- - ".travis.yml"
24
25
  - CHANGELOG.md
25
26
  - Gemfile
26
27
  - README.md
@@ -95,7 +96,7 @@ homepage: http://github.com/imanel/websocket-ruby
95
96
  licenses:
96
97
  - MIT
97
98
  metadata: {}
98
- post_install_message:
99
+ post_install_message:
99
100
  rdoc_options: []
100
101
  require_paths:
101
102
  - lib
@@ -110,37 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.7.7
115
- signing_key:
114
+ rubygems_version: 3.4.10
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