websocket-rack 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/CHANGELOG.md +6 -0
- data/README.md +3 -2
- data/lib/rack/websocket/handler/base/connection.rb +6 -2
- data/lib/rack/websocket/version.rb +2 -2
- data/spec/support/all_drafts.rb +5 -4
- data/spec/support/all_handlers.rb +26 -15
- data/spec/support/masked_messages.rb +2 -2
- data/spec/support/requests.rb +31 -0
- data/websocket-rack.gemspec +2 -2
- metadata +13 -13
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.3.3 / 2012-02-16
|
4
|
+
|
5
|
+
- postponse sending messages and closing connection to next tick(prevent locking rest of current request)
|
6
|
+
- support for WebSocket drafts 09-13 (currently proposed as standard)
|
7
|
+
- prevent blocking tests when invalid responsed is received
|
8
|
+
|
3
9
|
## 0.3.2 / 2011-12-13
|
4
10
|
|
5
11
|
- fix bug that resulted in 'location mismatch' error on Safari and iOS
|
data/README.md
CHANGED
@@ -164,7 +164,8 @@ end
|
|
164
164
|
|
165
165
|
### Which WebSocket drafts are supported:
|
166
166
|
|
167
|
-
Currently we support drafts -75 and -76 form old(hixie) numeration and all drafts from -00 to -
|
167
|
+
Currently we support drafts -75 and -76 form old(hixie) numeration and all drafts from -00 to -13 from current(ietf-hybi) numeration.
|
168
|
+
Please note that ietf-hybi-13 is currently proposed as final standard.
|
168
169
|
|
169
170
|
### Which Rack servers are supported?
|
170
171
|
|
@@ -192,4 +193,4 @@ This is bug in EventMachine < 1.0.0. Please consider updating to newer version o
|
|
192
193
|
|
193
194
|
Author: Bernard Potocki <<bernard.potocki@imanel.org>>
|
194
195
|
|
195
|
-
Released under MIT license.
|
196
|
+
Released under MIT license.
|
@@ -22,13 +22,17 @@ module Rack
|
|
22
22
|
# Overwrite send_data from EventMachine
|
23
23
|
# delegate send_data to rack server
|
24
24
|
def send_data(*args)
|
25
|
-
|
25
|
+
EM.next_tick do
|
26
|
+
@socket.send_data(*args)
|
27
|
+
end
|
26
28
|
end
|
27
29
|
|
28
30
|
# Overwrite close_connection from EventMachine
|
29
31
|
# delegate close_connection to rack server
|
30
32
|
def close_connection(*args)
|
31
|
-
|
33
|
+
EM.next_tick do
|
34
|
+
@socket.close_connection(*args)
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
#########################
|
data/spec/support/all_drafts.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
require 'timeout'
|
1
2
|
shared_examples_for 'all drafts' do
|
2
3
|
it "should accept incoming connection" do
|
3
4
|
conn = new_server_connection
|
4
5
|
conn.write(handshake_request)
|
5
|
-
conn.read(handshake_response.length).should eql(handshake_response)
|
6
|
+
timeout(1) { conn.read(handshake_response.length).should eql(handshake_response) }
|
6
7
|
end
|
7
8
|
it "should call 'on_open' on new connection" do
|
8
9
|
TestApp.any_instance.expects(:on_open)
|
@@ -30,14 +31,14 @@ shared_examples_for 'all drafts' do
|
|
30
31
|
TestApp.any_instance.expects(:on_message)
|
31
32
|
conn = new_server_connection
|
32
33
|
conn.write(handshake_request)
|
33
|
-
conn.read(handshake_response.length)
|
34
|
+
timeout(1) { conn.read(handshake_response.length) }
|
34
35
|
conn.write(message)
|
35
36
|
end
|
36
37
|
it "should call 'on_message' on connection sending data with proper env and message" do
|
37
38
|
TestApp.any_instance.expects(:on_message).once.with { |env, message| env.class == Hash && !env.keys.empty? && message == 'Hello' }
|
38
39
|
conn = new_server_connection
|
39
40
|
conn.write(handshake_request)
|
40
|
-
conn.read(handshake_response.length)
|
41
|
+
timeout(1) { conn.read(handshake_response.length) }
|
41
42
|
conn.write(message)
|
42
43
|
end
|
43
|
-
end
|
44
|
+
end
|
@@ -4,66 +4,77 @@ shared_examples_for 'all handlers' do
|
|
4
4
|
conn.write(flash_policy_request)
|
5
5
|
conn.read(flash_policy_response.length).should eql(flash_policy_response)
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
context 'for draft75' do
|
9
9
|
let(:handshake_request) { spec75_handshake_request }
|
10
10
|
let(:handshake_response) { spec75_handshake_response }
|
11
11
|
let(:message) { spec75_message }
|
12
|
-
|
12
|
+
|
13
13
|
it_should_behave_like 'all drafts'
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# Also draft00
|
17
17
|
context 'for draft76' do
|
18
18
|
let(:handshake_request) { spec76_handshake_request }
|
19
19
|
let(:handshake_response) { spec76_handshake_response }
|
20
20
|
let(:message) { spec76_message }
|
21
|
-
|
21
|
+
|
22
22
|
it_should_behave_like 'all drafts'
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# Drafts 01, 02 and 03 are pretty the same so one test for all
|
26
26
|
context 'for draft03' do
|
27
27
|
let(:handshake_request) { spec03_handshake_request }
|
28
28
|
let(:handshake_response) { spec03_handshake_response }
|
29
29
|
let(:message) { spec03_message }
|
30
|
-
|
30
|
+
|
31
31
|
it_should_behave_like 'all drafts'
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
context 'for draft05' do
|
35
35
|
let(:handshake_request) { spec05_handshake_request }
|
36
36
|
let(:handshake_response) { spec05_handshake_response }
|
37
37
|
let(:message) { spec05_message }
|
38
|
-
|
38
|
+
|
39
39
|
it_should_behave_like 'all drafts'
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
context 'for draft06' do
|
43
43
|
let(:handshake_request) { spec06_handshake_request }
|
44
44
|
let(:handshake_response) { spec06_handshake_response }
|
45
45
|
let(:message) { spec06_message }
|
46
|
-
|
46
|
+
|
47
47
|
it_should_behave_like 'all drafts'
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
context 'for draft07' do
|
51
51
|
let(:handshake_request) { spec07_handshake_request }
|
52
52
|
let(:handshake_response) { spec07_handshake_response }
|
53
53
|
let(:message) { spec07_unmasked_message }
|
54
54
|
let(:masked_message) { spec07_masked_message }
|
55
|
-
|
55
|
+
|
56
56
|
it_should_behave_like 'all drafts'
|
57
57
|
it_should_behave_like 'draft with masked messages'
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
context 'for draft08' do
|
61
61
|
let(:handshake_request) { spec08_handshake_request }
|
62
62
|
let(:handshake_response) { spec08_handshake_response }
|
63
63
|
let(:message) { spec08_unmasked_message }
|
64
64
|
let(:masked_message) { spec08_masked_message }
|
65
|
-
|
65
|
+
|
66
66
|
it_should_behave_like 'all drafts'
|
67
67
|
it_should_behave_like 'draft with masked messages'
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
|
+
# Drafts 09, 10, 11, 12 and 13 are pretty the same so one test for all
|
71
|
+
context 'for draft13' do
|
72
|
+
let(:handshake_request) { spec13_handshake_request }
|
73
|
+
let(:handshake_response) { spec13_handshake_response }
|
74
|
+
let(:message) { spec13_unmasked_message }
|
75
|
+
let(:masked_message) { spec13_masked_message }
|
76
|
+
|
77
|
+
it_should_behave_like 'all drafts'
|
78
|
+
it_should_behave_like 'draft with masked messages'
|
79
|
+
end
|
80
|
+
end
|
@@ -3,7 +3,7 @@ shared_examples_for 'draft with masked messages' do
|
|
3
3
|
TestApp.any_instance.expects(:on_message).once.with { |env, message| env.class == Hash && !env.keys.empty? && message == 'Hello' }
|
4
4
|
conn = new_server_connection
|
5
5
|
conn.write(handshake_request)
|
6
|
-
conn.read(handshake_response.length)
|
6
|
+
timeout(1) { conn.read(handshake_response.length) }
|
7
7
|
conn.write(masked_message)
|
8
8
|
end
|
9
|
-
end
|
9
|
+
end
|
data/spec/support/requests.rb
CHANGED
@@ -216,3 +216,34 @@ end
|
|
216
216
|
def spec08_masked_message
|
217
217
|
"\x81\x85\x37\xfa\x21\x3d\x7f\x9f\x4d\x51\x58"
|
218
218
|
end
|
219
|
+
|
220
|
+
def spec13_handshake_request
|
221
|
+
<<-EOF
|
222
|
+
GET /chat HTTP/1.1\r
|
223
|
+
Host: localhost:#{TEST_PORT}\r
|
224
|
+
Upgrade: websocket\r
|
225
|
+
Connection: Upgrade\r
|
226
|
+
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r
|
227
|
+
Origin: http://localhost:#{TEST_PORT}\r
|
228
|
+
Sec-WebSocket-Protocol: chat, superchat\r
|
229
|
+
Sec-WebSocket-Version: 13\r
|
230
|
+
\r
|
231
|
+
EOF
|
232
|
+
end
|
233
|
+
|
234
|
+
def spec13_handshake_response
|
235
|
+
<<-EOF
|
236
|
+
HTTP/1.1 101 Switching Protocols\r
|
237
|
+
Upgrade: websocket\r
|
238
|
+
Connection: Upgrade\r
|
239
|
+
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r
|
240
|
+
EOF
|
241
|
+
end
|
242
|
+
|
243
|
+
def spec13_unmasked_message
|
244
|
+
"\x81\x05\x48\x65\x6c\x6c\x6f"
|
245
|
+
end
|
246
|
+
|
247
|
+
def spec13_masked_message
|
248
|
+
"\x81\x85\x37\xfa\x21\x3d\x7f\x9f\x4d\x51\x58"
|
249
|
+
end
|
data/websocket-rack.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{Rack-based WebSocket server}
|
14
14
|
|
15
15
|
s.add_dependency 'rack'
|
16
|
-
s.add_dependency 'em-websocket', '~> 0.3.
|
16
|
+
s.add_dependency 'em-websocket', '~> 0.3.6'
|
17
17
|
s.add_dependency 'thin' # Temporary until we support more servers
|
18
18
|
s.add_development_dependency 'rspec', '~> 2.4.0'
|
19
19
|
s.add_development_dependency 'mocha'
|
@@ -22,4 +22,4 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
23
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
24
|
s.require_paths = ["lib"]
|
25
|
-
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: websocket-rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70187912377380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70187912377380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: em-websocket
|
27
|
-
requirement: &
|
27
|
+
requirement: &70187912376880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.3.
|
32
|
+
version: 0.3.6
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70187912376880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: thin
|
38
|
-
requirement: &
|
38
|
+
requirement: &70187912376460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70187912376460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70187912375920 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.4.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70187912375920
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mocha
|
60
|
-
requirement: &
|
60
|
+
requirement: &70187912375500 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70187912375500
|
69
69
|
description: Rack-based WebSocket server
|
70
70
|
email:
|
71
71
|
- bernard.potocki@imanel.org
|