websocket 1.2.5 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +1 -0
- data/.rubocop.yml +4 -1
- data/.travis.yml +1 -5
- data/CHANGELOG.md +8 -0
- data/Gemfile +5 -3
- data/Rakefile +3 -1
- data/lib/websocket.rb +3 -1
- data/lib/websocket/error.rb +2 -0
- data/lib/websocket/exception_handler.rb +2 -0
- data/lib/websocket/frame.rb +2 -0
- data/lib/websocket/frame/base.rb +2 -0
- data/lib/websocket/frame/data.rb +3 -1
- data/lib/websocket/frame/handler.rb +2 -0
- data/lib/websocket/frame/handler/base.rb +4 -2
- data/lib/websocket/frame/handler/handler03.rb +5 -4
- data/lib/websocket/frame/handler/handler04.rb +1 -0
- data/lib/websocket/frame/handler/handler05.rb +1 -0
- data/lib/websocket/frame/handler/handler07.rb +2 -1
- data/lib/websocket/frame/handler/handler75.rb +2 -1
- data/lib/websocket/frame/incoming.rb +2 -0
- data/lib/websocket/frame/incoming/client.rb +2 -0
- data/lib/websocket/frame/incoming/server.rb +2 -0
- data/lib/websocket/frame/outgoing.rb +2 -0
- data/lib/websocket/frame/outgoing/client.rb +2 -0
- data/lib/websocket/frame/outgoing/server.rb +2 -0
- data/lib/websocket/handshake.rb +2 -0
- data/lib/websocket/handshake/base.rb +12 -3
- data/lib/websocket/handshake/client.rb +2 -0
- data/lib/websocket/handshake/handler.rb +2 -0
- data/lib/websocket/handshake/handler/base.rb +2 -0
- data/lib/websocket/handshake/handler/client.rb +2 -0
- data/lib/websocket/handshake/handler/client01.rb +2 -0
- data/lib/websocket/handshake/handler/client04.rb +4 -2
- data/lib/websocket/handshake/handler/client11.rb +2 -0
- data/lib/websocket/handshake/handler/client75.rb +4 -2
- data/lib/websocket/handshake/handler/client76.rb +4 -2
- data/lib/websocket/handshake/handler/server.rb +2 -0
- data/lib/websocket/handshake/handler/server04.rb +4 -2
- data/lib/websocket/handshake/handler/server75.rb +4 -2
- data/lib/websocket/handshake/handler/server76.rb +2 -0
- data/lib/websocket/handshake/server.rb +2 -0
- data/lib/websocket/nice_inspect.rb +2 -0
- data/lib/websocket/version.rb +3 -1
- data/spec/frame/incoming_03_spec.rb +18 -16
- data/spec/frame/incoming_04_spec.rb +18 -16
- data/spec/frame/incoming_05_spec.rb +20 -18
- data/spec/frame/incoming_07_spec.rb +22 -20
- data/spec/frame/incoming_75_spec.rb +11 -9
- data/spec/frame/incoming_common_spec.rb +1 -0
- data/spec/frame/masking_spec.rb +1 -0
- data/spec/frame/outgoing_03_spec.rb +10 -8
- data/spec/frame/outgoing_04_spec.rb +10 -8
- data/spec/frame/outgoing_05_spec.rb +10 -8
- data/spec/frame/outgoing_07_spec.rb +11 -9
- data/spec/frame/outgoing_75_spec.rb +6 -4
- data/spec/frame/outgoing_common_spec.rb +1 -0
- data/spec/handshake/client_04_spec.rb +6 -4
- data/spec/handshake/client_11_spec.rb +3 -1
- data/spec/handshake/client_75_spec.rb +4 -2
- data/spec/handshake/client_76_spec.rb +4 -2
- data/spec/handshake/server_04_spec.rb +4 -2
- data/spec/handshake/server_75_spec.rb +4 -2
- data/spec/handshake/server_76_spec.rb +4 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/support/all_client_drafts.rb +2 -0
- data/spec/support/all_server_drafts.rb +2 -0
- data/spec/support/frames_base.rb +2 -0
- data/spec/support/handshake_requests.rb +65 -63
- data/spec/support/incoming_frames.rb +2 -0
- data/spec/support/outgoing_frames.rb +2 -0
- data/spec/support/overwrites.rb +2 -0
- data/websocket.gemspec +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9fa1e04675b3abf21352767a5b1075b77de4dff1670d6644d65b17d09daef059
|
4
|
+
data.tar.gz: dbef4fe08a9ba610b68cd6ab92f2674ab18a4833874040207cac63742ead0100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9874d45a9b3bd2e773bc05540de06f1b2e710fa32bc0ac7da582e77f8e20f79f7d3e9863be9bea590e0b6b741e5f8692f39d483061570398cdae3303fb160ac4
|
7
|
+
data.tar.gz: bac88133308b1f2ce15f27de62ff74309189f2f9ccc9fd9ba006aaa3b936fc13a8e51f92bc2728c1ce52216df4ec2ac9845f8e31a2ef8217dc6e368ae98db515
|
data/.codeclimate.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -2,7 +2,7 @@ require: rubocop-rspec
|
|
2
2
|
|
3
3
|
AllCops:
|
4
4
|
DisplayCopNames: true
|
5
|
-
TargetRubyVersion: 2.
|
5
|
+
TargetRubyVersion: 2.3
|
6
6
|
|
7
7
|
# Target: 15
|
8
8
|
Metrics/AbcSize:
|
@@ -40,6 +40,9 @@ Metrics/PerceivedComplexity:
|
|
40
40
|
- lib/websocket/frame/handler/handler75.rb
|
41
41
|
- spec/support/handshake_requests.rb
|
42
42
|
|
43
|
+
RSpec/ContextWording:
|
44
|
+
Enabled: false
|
45
|
+
|
43
46
|
RSpec/DescribeClass:
|
44
47
|
Enabled: false
|
45
48
|
|
data/.travis.yml
CHANGED
@@ -2,10 +2,9 @@ dist: trusty
|
|
2
2
|
language: ruby
|
3
3
|
script: "bundle exec rake"
|
4
4
|
rvm:
|
5
|
-
- 2.1
|
6
|
-
- 2.2
|
7
5
|
- 2.3
|
8
6
|
- 2.4
|
7
|
+
- 2.5
|
9
8
|
- ruby-head
|
10
9
|
- jruby-9.1.9.0 # https://github.com/travis-ci/travis-ci/issues/8446
|
11
10
|
- jruby-head
|
@@ -16,6 +15,3 @@ matrix:
|
|
16
15
|
- rvm: ruby-head
|
17
16
|
- rvm: jruby-head
|
18
17
|
- rvm: rbx-3
|
19
|
-
|
20
|
-
before_install:
|
21
|
-
- gem update bundler
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'http://rubygems.org'
|
2
4
|
|
3
5
|
group :development do
|
4
6
|
gem 'rake'
|
5
|
-
gem 'rspec', '~> 3.
|
7
|
+
gem 'rspec', '~> 3.7'
|
6
8
|
|
7
9
|
# Use same version as Code Climate for consistency with CI
|
8
10
|
# https://github.com/codeclimate/codeclimate-rubocop/blob/master/Gemfile.lock
|
9
|
-
gem 'rubocop', '0.
|
10
|
-
gem 'rubocop-rspec', '1.
|
11
|
+
gem 'rubocop', '0.52.1', require: false
|
12
|
+
gem 'rubocop-rspec', '1.21.0', require: false
|
11
13
|
end
|
12
14
|
|
13
15
|
gemspec
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler'
|
2
4
|
require 'rspec/core/rake_task'
|
3
5
|
require 'rubocop/rake_task'
|
@@ -11,7 +13,7 @@ end
|
|
11
13
|
|
12
14
|
RuboCop::RakeTask.new
|
13
15
|
|
14
|
-
task default: %i
|
16
|
+
task default: %i[spec rubocop]
|
15
17
|
|
16
18
|
namespace :autobahn do
|
17
19
|
desc 'Run autobahn tests for client'
|
data/lib/websocket.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# WebSocket protocol implementation in Ruby
|
2
4
|
# This module does not provide a WebSocket server or client, but is made for using
|
3
5
|
# in http servers or clients to provide WebSocket support.
|
@@ -6,7 +8,7 @@
|
|
6
8
|
module WebSocket
|
7
9
|
# Default WebSocket version to use
|
8
10
|
DEFAULT_VERSION = 13
|
9
|
-
ROOT =
|
11
|
+
ROOT = __dir__
|
10
12
|
|
11
13
|
autoload :Error, "#{ROOT}/websocket/error"
|
12
14
|
autoload :ExceptionHandler, "#{ROOT}/websocket/exception_handler"
|
data/lib/websocket/error.rb
CHANGED
data/lib/websocket/frame.rb
CHANGED
data/lib/websocket/frame/base.rb
CHANGED
data/lib/websocket/frame/data.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WebSocket
|
2
4
|
module Frame
|
3
5
|
class Data < String
|
@@ -11,7 +13,7 @@ module WebSocket
|
|
11
13
|
|
12
14
|
# Convert all arguments to ASCII-8BIT for easier traversing
|
13
15
|
def convert_args(args)
|
14
|
-
args.
|
16
|
+
args.collect { |arg| arg.dup.force_encoding('ASCII-8BIT') }
|
15
17
|
end
|
16
18
|
|
17
19
|
# Extract mask from 4 first bytes according to spec
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WebSocket
|
2
4
|
module Frame
|
3
5
|
module Handler
|
@@ -24,14 +26,14 @@ module WebSocket
|
|
24
26
|
# @param [Symbol] frame_type Frame type
|
25
27
|
# @return [Boolean] True if given frame type is control frame
|
26
28
|
def control_frame?(frame_type)
|
27
|
-
!%i
|
29
|
+
!%i[text binary continuation].include?(frame_type)
|
28
30
|
end
|
29
31
|
|
30
32
|
# Check if frame is one of data frames
|
31
33
|
# @param [Symbol] frame_type Frame type
|
32
34
|
# @return [Boolean] True if given frame type is data frame
|
33
35
|
def data_frame?(frame_type)
|
34
|
-
%i
|
36
|
+
%i[text binary].include?(frame_type)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'securerandom'
|
4
5
|
|
@@ -21,7 +22,7 @@ module WebSocket
|
|
21
22
|
|
22
23
|
# @see WebSocket::Frame::Base#supported_frames
|
23
24
|
def supported_frames
|
24
|
-
%i
|
25
|
+
%i[text binary close ping pong]
|
25
26
|
end
|
26
27
|
|
27
28
|
# @see WebSocket::Frame::Handler::Base#encode_frame
|
@@ -89,14 +90,14 @@ module WebSocket
|
|
89
90
|
def encode_header
|
90
91
|
mask = @frame.outgoing_masking? ? 0b10000000 : 0b00000000
|
91
92
|
|
92
|
-
output = ''
|
93
|
+
output = +''
|
93
94
|
output << (type_to_opcode(@frame.type) | (fin ? 0b10000000 : 0b00000000)) # since more, rsv1-3 are 0 and 0x80 for Draft 4
|
94
95
|
output << encode_payload_length(@frame.data.size, mask)
|
95
96
|
output
|
96
97
|
end
|
97
98
|
|
98
99
|
def encode_payload_length(length, mask)
|
99
|
-
output = ''
|
100
|
+
output = +''
|
100
101
|
if length <= 125
|
101
102
|
output << (length | mask) # since rsv4 is 0
|
102
103
|
elsif length < 65_536 # write 2 byte length
|
@@ -197,7 +198,7 @@ module WebSocket
|
|
197
198
|
end
|
198
199
|
|
199
200
|
def decode_continuation_frame(application_data, frame_type)
|
200
|
-
@application_data_buffer ||= ''
|
201
|
+
@application_data_buffer ||= +''
|
201
202
|
@application_data_buffer << application_data
|
202
203
|
@frame_type ||= frame_type
|
203
204
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: binary
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module WebSocket
|
4
5
|
module Frame
|
@@ -6,7 +7,7 @@ module WebSocket
|
|
6
7
|
class Handler75 < Base
|
7
8
|
# @see WebSocket::Frame::Base#supported_frames
|
8
9
|
def supported_frames
|
9
|
-
%i
|
10
|
+
%i[text close]
|
10
11
|
end
|
11
12
|
|
12
13
|
# @see WebSocket::Frame::Handler::Base#encode_frame
|
data/lib/websocket/handshake.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WebSocket
|
2
4
|
module Handshake
|
3
5
|
# @abstract Subclass and override to implement custom handshakes
|
@@ -11,12 +13,19 @@ module WebSocket
|
|
11
13
|
|
12
14
|
# Initialize new WebSocket Handshake and set it's state to :new
|
13
15
|
def initialize(args = {})
|
14
|
-
args.each
|
16
|
+
args.each do |k, v|
|
17
|
+
value = begin
|
18
|
+
v.dup
|
19
|
+
rescue TypeError
|
20
|
+
v
|
21
|
+
end
|
22
|
+
instance_variable_set("@#{k}", value)
|
23
|
+
end
|
15
24
|
|
16
25
|
@state = :new
|
17
26
|
@handler = nil
|
18
27
|
|
19
|
-
@data = ''
|
28
|
+
@data = +''
|
20
29
|
@headers ||= {}
|
21
30
|
@protocols ||= []
|
22
31
|
end
|
@@ -62,7 +71,7 @@ module WebSocket
|
|
62
71
|
# @example
|
63
72
|
# @handshake.uri #=> "ws://example.com/path?query=true"
|
64
73
|
def uri
|
65
|
-
uri = secure ? 'wss://' : 'ws://'
|
74
|
+
uri = String.new(secure ? 'wss://' : 'ws://')
|
66
75
|
uri << host
|
67
76
|
uri << ":#{port}" if port
|
68
77
|
uri << path
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'digest/sha1'
|
2
4
|
require 'base64'
|
3
5
|
|
@@ -15,8 +17,8 @@ module WebSocket
|
|
15
17
|
# @see WebSocket::Handshake::Handler::Base#handshake_keys
|
16
18
|
def handshake_keys
|
17
19
|
keys = [
|
18
|
-
%w
|
19
|
-
%w
|
20
|
+
%w[Upgrade websocket],
|
21
|
+
%w[Connection Upgrade]
|
20
22
|
]
|
21
23
|
host = @handshake.host
|
22
24
|
host += ":#{@handshake.port}" if @handshake.port
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WebSocket
|
2
4
|
module Handshake
|
3
5
|
module Handler
|
@@ -12,8 +14,8 @@ module WebSocket
|
|
12
14
|
# @see WebSocket::Handshake::Handler::Base#handshake_keys
|
13
15
|
def handshake_keys
|
14
16
|
keys = [
|
15
|
-
%w
|
16
|
-
%w
|
17
|
+
%w[Upgrade WebSocket],
|
18
|
+
%w[Connection Upgrade]
|
17
19
|
]
|
18
20
|
host = @handshake.host
|
19
21
|
host += ":#{@handshake.port}" if @handshake.port
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'digest/md5'
|
2
4
|
|
3
5
|
module WebSocket
|
@@ -72,12 +74,12 @@ module WebSocket
|
|
72
74
|
# @param [String] name of key. Will be used to set number variable needed later. Valid values: key1, key2
|
73
75
|
# @return [String] generated key
|
74
76
|
def generate_key(key)
|
75
|
-
spaces =
|
77
|
+
spaces = rand(1..12)
|
76
78
|
max = 0xffffffff / spaces
|
77
79
|
number = rand(max + 1)
|
78
80
|
instance_variable_set("@#{key}_number", number)
|
79
81
|
key = (number * spaces).to_s
|
80
|
-
(1
|
82
|
+
rand(1..12).times do
|
81
83
|
char = NOISE_CHARS[rand(NOISE_CHARS.size)]
|
82
84
|
pos = rand(key.size + 1)
|
83
85
|
key[pos...pos] = char
|