websocket 1.1.4 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -6
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -1
- data/README.md +10 -6
- data/Rakefile +1 -1
- data/lib/websocket.rb +1 -1
- data/lib/websocket/exception_handler.rb +6 -0
- data/lib/websocket/frame/base.rb +1 -1
- data/lib/websocket/frame/data.rb +11 -9
- data/lib/websocket/frame/handler.rb +1 -1
- data/lib/websocket/frame/handler/handler03.rb +17 -17
- data/lib/websocket/frame/handler/handler07.rb +8 -8
- data/lib/websocket/frame/handler/handler75.rb +8 -7
- data/lib/websocket/frame/incoming.rb +1 -1
- data/lib/websocket/frame/outgoing.rb +1 -1
- data/lib/websocket/handshake/base.rb +7 -7
- data/lib/websocket/handshake/client.rb +5 -3
- data/lib/websocket/handshake/handler/base.rb +5 -5
- data/lib/websocket/handshake/handler/client.rb +6 -1
- data/lib/websocket/handshake/handler/client04.rb +7 -6
- data/lib/websocket/handshake/handler/client75.rb +5 -4
- data/lib/websocket/handshake/handler/client76.rb +5 -5
- data/lib/websocket/handshake/handler/server04.rb +11 -6
- data/lib/websocket/handshake/handler/server75.rb +5 -5
- data/lib/websocket/handshake/handler/server76.rb +9 -9
- data/lib/websocket/handshake/server.rb +25 -24
- data/lib/websocket/version.rb +1 -1
- data/spec/frame/incoming_03_spec.rb +25 -25
- data/spec/frame/incoming_04_spec.rb +25 -25
- data/spec/frame/incoming_05_spec.rb +29 -29
- data/spec/frame/incoming_07_spec.rb +31 -31
- data/spec/frame/incoming_75_spec.rb +13 -13
- data/spec/frame/incoming_common_spec.rb +12 -13
- data/spec/frame/masking_spec.rb +10 -10
- data/spec/frame/outgoing_03_spec.rb +17 -17
- data/spec/frame/outgoing_04_spec.rb +17 -17
- data/spec/frame/outgoing_05_spec.rb +17 -17
- data/spec/frame/outgoing_07_spec.rb +19 -19
- data/spec/frame/outgoing_75_spec.rb +9 -9
- data/spec/frame/outgoing_common_spec.rb +7 -8
- data/spec/handshake/client_04_spec.rb +9 -9
- data/spec/handshake/client_75_spec.rb +2 -2
- data/spec/handshake/client_76_spec.rb +9 -9
- data/spec/handshake/server_04_spec.rb +5 -5
- data/spec/handshake/server_75_spec.rb +1 -1
- data/spec/handshake/server_76_spec.rb +21 -21
- data/spec/spec_helper.rb +4 -1
- data/spec/support/all_client_drafts.rb +62 -52
- data/spec/support/all_server_drafts.rb +49 -49
- data/spec/support/handshake_requests.rb +16 -16
- data/spec/support/incoming_frames.rb +28 -28
- data/spec/support/outgoing_frames.rb +10 -10
- data/websocket.gemspec +1 -1
- metadata +42 -22
- checksums.yaml +0 -7
@@ -1,11 +1,11 @@
|
|
1
1
|
def client_handshake_75(args = {})
|
2
2
|
<<-EOF
|
3
|
-
GET #{args[:path] ||
|
3
|
+
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
|
4
4
|
Upgrade: WebSocket\r
|
5
5
|
Connection: Upgrade\r
|
6
|
-
Host: #{args[:host] ||
|
6
|
+
Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
|
7
7
|
Origin: http://example.com\r
|
8
|
-
\r
|
8
|
+
#{(args[:headers] || {}).map{|key, value| "#{key}: #{value}\r\n"}.join('')}\r
|
9
9
|
EOF
|
10
10
|
end
|
11
11
|
|
@@ -15,22 +15,22 @@ HTTP/1.1 101 Web Socket Protocol Handshake\r
|
|
15
15
|
Upgrade: WebSocket\r
|
16
16
|
Connection: Upgrade\r
|
17
17
|
WebSocket-Origin: http://example.com\r
|
18
|
-
WebSocket-Location: ws#{args[:secure] ?
|
18
|
+
WebSocket-Location: ws#{args[:secure] ? 's' : ''}://#{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}#{args[:path] || '/demo'}\r
|
19
19
|
\r
|
20
20
|
EOF
|
21
21
|
end
|
22
22
|
|
23
23
|
def client_handshake_76(args = {})
|
24
24
|
request = <<-EOF
|
25
|
-
GET #{args[:path] ||
|
25
|
+
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
|
26
26
|
Upgrade: WebSocket\r
|
27
27
|
Connection: Upgrade\r
|
28
|
-
Host: #{args[:host] ||
|
28
|
+
Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
|
29
29
|
Origin: http://example.com\r
|
30
|
-
Sec-WebSocket-Key1: #{args[:key1] ||
|
31
|
-
Sec-WebSocket-Key2: #{args[:key2] ||
|
30
|
+
#{(args[:headers] || {}).map{|key, value| "#{key}: #{value}\r\n"}.join('')}Sec-WebSocket-Key1: #{args[:key1] || '4 @1 46546xW%0l 1 5'}\r
|
31
|
+
Sec-WebSocket-Key2: #{args[:key2] || '12998 5 Y3 1 .P00'}\r
|
32
32
|
\r
|
33
|
-
#{args[:key3] ||
|
33
|
+
#{args[:key3] || '^n:ds[4U'}
|
34
34
|
EOF
|
35
35
|
request[0..-2]
|
36
36
|
end
|
@@ -41,7 +41,7 @@ HTTP/1.1 101 WebSocket Protocol Handshake\r
|
|
41
41
|
Upgrade: WebSocket\r
|
42
42
|
Connection: Upgrade\r
|
43
43
|
Sec-WebSocket-Origin: http://example.com\r
|
44
|
-
Sec-WebSocket-Location: ws#{args[:secure] ?
|
44
|
+
Sec-WebSocket-Location: ws#{args[:secure] ? 's' : ''}://#{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}#{args[:path] || '/demo'}\r
|
45
45
|
\r
|
46
46
|
#{args[:challenge] || "8jKS'y:G*Co,Wxa-"}
|
47
47
|
EOF
|
@@ -50,13 +50,13 @@ end
|
|
50
50
|
|
51
51
|
def client_handshake_04(args = {})
|
52
52
|
<<-EOF
|
53
|
-
GET #{args[:path] ||
|
53
|
+
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
|
54
54
|
Upgrade: websocket\r
|
55
55
|
Connection: Upgrade\r
|
56
|
-
Host: #{args[:host] ||
|
57
|
-
Sec-WebSocket-Origin: http://example.com\r
|
58
|
-
Sec-WebSocket-Version: #{args[:version] ||
|
59
|
-
Sec-WebSocket-Key: #{args[:key] ||
|
56
|
+
Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
|
57
|
+
#{(args[:headers] || {}).map{|key, value| "#{key}: #{value}\r\n"}.join('')}Sec-WebSocket-Origin: http://example.com\r
|
58
|
+
Sec-WebSocket-Version: #{args[:version] || '4'}\r
|
59
|
+
Sec-WebSocket-Key: #{args[:key] || 'dGhlIHNhbXBsZSBub25jZQ=='}\r
|
60
60
|
\r
|
61
61
|
EOF
|
62
62
|
end
|
@@ -66,7 +66,7 @@ def server_handshake_04(args = {})
|
|
66
66
|
HTTP/1.1 101 Switching Protocols\r
|
67
67
|
Upgrade: websocket\r
|
68
68
|
Connection: Upgrade\r
|
69
|
-
Sec-WebSocket-Accept: #{args[:accept] ||
|
69
|
+
Sec-WebSocket-Accept: #{args[:accept] || 's3pPLMBiTxaQ9kYGzzhZRbK+xOo='}\r
|
70
70
|
\r
|
71
71
|
EOF
|
72
72
|
end
|
@@ -1,54 +1,54 @@
|
|
1
|
-
shared_examples_for 'valid_incoming_frame' do
|
2
|
-
let(:decoded_text_array) {
|
1
|
+
RSpec.shared_examples_for 'valid_incoming_frame' do
|
2
|
+
let(:decoded_text_array) { Array(decoded_text) }
|
3
3
|
let(:frame_type_array) { Array(frame_type) }
|
4
4
|
|
5
|
-
its(:class) {
|
6
|
-
its(:data) {
|
7
|
-
its(:version) {
|
8
|
-
its(:type) {
|
9
|
-
its(:decoded?) {
|
10
|
-
its(:to_s) {
|
5
|
+
its(:class) { is_expected.to eql(WebSocket::Frame::Incoming) }
|
6
|
+
its(:data) { is_expected.to eql(encoded_text || '') }
|
7
|
+
its(:version) { is_expected.to eql(version) }
|
8
|
+
its(:type) { is_expected.to be_nil }
|
9
|
+
its(:decoded?) { is_expected.to be false }
|
10
|
+
its(:to_s) { is_expected.to eql(encoded_text || '') }
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'should have specified number of returned frames' do
|
13
13
|
decoded_text_array.each_with_index do |da, index|
|
14
14
|
n = subject.next
|
15
|
-
n.
|
16
|
-
n.class.
|
15
|
+
expect(n).not_to be_nil, "Should return frame for #{da}, #{frame_type_array[index]}"
|
16
|
+
expect(n.class).to eql(WebSocket::Frame::Incoming), "Should be WebSocket::Frame::Incoming, #{n} received instead"
|
17
17
|
end
|
18
|
-
subject.next.
|
18
|
+
expect(subject.next).to be_nil
|
19
19
|
if error.is_a?(Class)
|
20
|
-
subject.error.
|
20
|
+
expect(subject.error).to eql(error.new.message)
|
21
21
|
else
|
22
|
-
subject.error.
|
22
|
+
expect(subject.error).to eql(error)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it 'should return valid decoded frame for each specified decoded texts' do
|
27
27
|
decoded_text_array.each_with_index do |da, index|
|
28
28
|
f = subject.next
|
29
|
-
f.decoded
|
30
|
-
f.type.
|
31
|
-
f.code.
|
32
|
-
f.to_s.
|
29
|
+
expect(f.decoded?).to be true
|
30
|
+
expect(f.type).to eql(frame_type_array[index])
|
31
|
+
expect(f.code).to eql(close_code) if defined?(close_code)
|
32
|
+
expect(f.to_s).to eql(da)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context
|
37
|
-
before { WebSocket.should_raise = true }
|
38
|
-
after { WebSocket.should_raise = false }
|
36
|
+
context 'with raising' do
|
37
|
+
before(:each) { WebSocket.should_raise = true }
|
38
|
+
after(:each) { WebSocket.should_raise = false }
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'should have specified number of returned frames' do
|
41
41
|
expect do
|
42
42
|
decoded_text_array.each_with_index do |da, index|
|
43
43
|
n = subject.next
|
44
|
-
n.
|
45
|
-
n.class.
|
44
|
+
expect(n).not_to be_nil, "Should return frame for #{da}, #{frame_type_array[index]}"
|
45
|
+
expect(n.class).to eql(WebSocket::Frame::Incoming), "Should be WebSocket::Frame::Incoming, #{n} received instead"
|
46
46
|
end
|
47
|
-
subject.next.
|
47
|
+
expect(subject.next).to be_nil
|
48
48
|
if error.is_a?(Class)
|
49
|
-
subject.error.
|
49
|
+
expect(subject.error).to eql(error.new.message)
|
50
50
|
else
|
51
|
-
subject.error.
|
51
|
+
expect(subject.error).to eql(error)
|
52
52
|
end
|
53
53
|
end.to raise_error(error) if error
|
54
54
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
shared_examples_for 'valid_outgoing_frame' do
|
2
|
-
its(:class) {
|
3
|
-
its(:version) {
|
4
|
-
its(:type) {
|
5
|
-
its(:data) {
|
6
|
-
its(:to_s) {
|
1
|
+
RSpec.shared_examples_for 'valid_outgoing_frame' do
|
2
|
+
its(:class) { is_expected.to eql(WebSocket::Frame::Outgoing) }
|
3
|
+
its(:version) { is_expected.to eql(version) }
|
4
|
+
its(:type) { is_expected.to eql(frame_type) }
|
5
|
+
its(:data) { is_expected.to eql(decoded_text) }
|
6
|
+
its(:to_s) { is_expected.to eql(encoded_text) }
|
7
7
|
|
8
|
-
context
|
9
|
-
before { subject.to_s }
|
10
|
-
its(:error) {
|
11
|
-
its(:require_sending?) {
|
8
|
+
context 'after parsing' do
|
9
|
+
before(:each) { subject.to_s }
|
10
|
+
its(:error) { is_expected.to eql(error) }
|
11
|
+
its(:require_sending?) { is_expected.to eql(require_sending) }
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
data/websocket.gemspec
CHANGED
@@ -14,6 +14,6 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
end
|
metadata
CHANGED
@@ -1,24 +1,35 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: websocket
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 1.2.0
|
5
10
|
platform: ruby
|
6
|
-
authors:
|
11
|
+
authors:
|
7
12
|
- Bernard Potocki
|
8
13
|
autorequire:
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
|
-
|
16
|
+
|
17
|
+
date: 2014-07-24 00:00:00 +02:00
|
18
|
+
default_executable:
|
12
19
|
dependencies: []
|
20
|
+
|
13
21
|
description: Universal Ruby library to handle WebSocket protocol
|
14
|
-
email:
|
22
|
+
email:
|
15
23
|
- bernard.potocki@imanel.org
|
16
24
|
executables: []
|
25
|
+
|
17
26
|
extensions: []
|
27
|
+
|
18
28
|
extra_rdoc_files: []
|
19
|
-
|
20
|
-
|
21
|
-
-
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- .travis.yml
|
22
33
|
- CHANGELOG.md
|
23
34
|
- Gemfile
|
24
35
|
- README.md
|
@@ -86,30 +97,39 @@ files:
|
|
86
97
|
- spec/support/outgoing_frames.rb
|
87
98
|
- spec/support/overwrites.rb
|
88
99
|
- websocket.gemspec
|
100
|
+
has_rdoc: true
|
89
101
|
homepage: http://github.com/imanel/websocket-ruby
|
90
102
|
licenses: []
|
91
|
-
|
103
|
+
|
92
104
|
post_install_message:
|
93
105
|
rdoc_options: []
|
94
|
-
|
106
|
+
|
107
|
+
require_paths:
|
95
108
|
- lib
|
96
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
-
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
98
112
|
- - ">="
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
|
102
|
-
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
103
120
|
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
106
125
|
requirements: []
|
126
|
+
|
107
127
|
rubyforge_project:
|
108
|
-
rubygems_version:
|
128
|
+
rubygems_version: 1.3.7.1
|
109
129
|
signing_key:
|
110
|
-
specification_version:
|
130
|
+
specification_version: 3
|
111
131
|
summary: Universal Ruby library to handle WebSocket protocol
|
112
|
-
test_files:
|
132
|
+
test_files:
|
113
133
|
- spec/frame/incoming_03_spec.rb
|
114
134
|
- spec/frame/incoming_04_spec.rb
|
115
135
|
- spec/frame/incoming_05_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 3d5e949888cd78a33c1418916aa773e1408a9302
|
4
|
-
data.tar.gz: d74a71f238b56bf1711dd7b117cde1d3cf5bc037
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 5a7e71df6d11c0fc817d094845dd059a0d2ec00586f7373a714bde6d3ee9dbf15e27ecbb94c00aef039f2fc85da34933b21110d767429a8aa2bce35cb192cd9f
|
7
|
-
data.tar.gz: 48e22828b858a469f179bcf08ecc8acbc427f6f863e1cf38a3ca3e5b36a9a4c06a93a72b024e6dd5b7f1b11864cb6abefbef6334c7f789cfbe1451e766c0a0ed
|