libwebsocket 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +88 -0
- data/Rakefile +26 -0
- data/examples/eventmachine_server.rb +36 -0
- data/examples/plain_client.rb +59 -0
- data/examples/thin_server.rb +69 -0
- data/lib/libwebsocket.rb +17 -0
- data/lib/libwebsocket/cookie.rb +60 -0
- data/lib/libwebsocket/cookie/request.rb +48 -0
- data/lib/libwebsocket/cookie/response.rb +44 -0
- data/lib/libwebsocket/frame.rb +67 -0
- data/lib/libwebsocket/handshake.rb +28 -0
- data/lib/libwebsocket/handshake/client.rb +129 -0
- data/lib/libwebsocket/handshake/server.rb +114 -0
- data/lib/libwebsocket/message.rb +167 -0
- data/lib/libwebsocket/request.rb +288 -0
- data/lib/libwebsocket/response.rb +215 -0
- data/lib/libwebsocket/stateful.rb +24 -0
- data/lib/libwebsocket/url.rb +67 -0
- data/test/libwebsocket/cookie/request.rb +37 -0
- data/test/libwebsocket/cookie/response.rb +32 -0
- data/test/libwebsocket/handshake/test_client.rb +64 -0
- data/test/libwebsocket/handshake/test_server.rb +39 -0
- data/test/libwebsocket/test_cookie.rb +21 -0
- data/test/libwebsocket/test_frame.rb +65 -0
- data/test/libwebsocket/test_message.rb +16 -0
- data/test/libwebsocket/test_request_75.rb +145 -0
- data/test/libwebsocket/test_request_76.rb +122 -0
- data/test/libwebsocket/test_request_common.rb +26 -0
- data/test/libwebsocket/test_response_75.rb +80 -0
- data/test/libwebsocket/test_response_76.rb +115 -0
- data/test/libwebsocket/test_response_common.rb +17 -0
- data/test/libwebsocket/test_url.rb +49 -0
- data/test/test_helper.rb +4 -0
- metadata +116 -0
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRequest76 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_parse
|
6
|
+
req = LibWebSocket::Request.new
|
7
|
+
assert !req.done?
|
8
|
+
assert req.parse('')
|
9
|
+
assert req.parse("GET /demo HTTP/1.1\x0d\x0a")
|
10
|
+
assert_equal 'fields', req.state
|
11
|
+
|
12
|
+
assert req.parse("Upgrade: WebSocket\x0d\x0a")
|
13
|
+
assert_equal 'fields', req.state
|
14
|
+
assert req.parse("Connection: Upgrade\x0d\x0a")
|
15
|
+
assert_equal 'fields', req.state
|
16
|
+
assert req.parse("Host: example.com\x0d\x0a")
|
17
|
+
assert_equal 'fields', req.state
|
18
|
+
assert req.parse("Origin: http://example.com\x0d\x0a")
|
19
|
+
assert_equal 'fields', req.state
|
20
|
+
assert req.parse(
|
21
|
+
"Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8\x0d\x0a")
|
22
|
+
assert req.parse(
|
23
|
+
"Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0\x0d\x0a")
|
24
|
+
assert_equal 'fields', req.state
|
25
|
+
assert req.parse("\x0d\x0aTm[K T2u")
|
26
|
+
assert_equal 'done', req.state
|
27
|
+
assert_equal 155712099, req.number1
|
28
|
+
assert_equal 173347027, req.number2
|
29
|
+
assert_equal 'Tm[K T2u', req.challenge
|
30
|
+
|
31
|
+
assert_equal 76, req.version
|
32
|
+
assert_equal '/demo', req.resource_name
|
33
|
+
assert_equal 'example.com', req.host
|
34
|
+
assert_equal 'http://example.com', req.origin
|
35
|
+
assert_equal 'fQJ,fN/4F4!~K~MH', req.checksum
|
36
|
+
assert_equal 76, req.version
|
37
|
+
assert_equal '/demo', req.resource_name
|
38
|
+
assert_equal 'example.com', req.host
|
39
|
+
assert_equal 'http://example.com', req.origin
|
40
|
+
assert_equal 'fQJ,fN/4F4!~K~MH', req.checksum
|
41
|
+
|
42
|
+
req = LibWebSocket::Request.new
|
43
|
+
assert req.parse("GET /demo HTTP/1.1\x0d\x0a")
|
44
|
+
assert req.parse("Upgrade: WebSocket\x0d\x0a")
|
45
|
+
assert req.parse("Connection: Upgrade\x0d\x0a")
|
46
|
+
assert req.parse("Host: example.com\x0d\x0a")
|
47
|
+
assert req.parse("Origin: http://example.com\x0d\x0a")
|
48
|
+
assert req.parse("Sec-WebSocket-Protocol: sample\x0d\x0a")
|
49
|
+
assert req.parse(
|
50
|
+
"Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8\x0d\x0a")
|
51
|
+
assert req.parse(
|
52
|
+
"Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0\x0d\x0a")
|
53
|
+
assert req.parse("\x0d\x0aTm[K T2u")
|
54
|
+
assert req.done?
|
55
|
+
assert_equal 'sample', req.subprotocol
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_checksum
|
59
|
+
req = LibWebSocket::Request.new(
|
60
|
+
:host => 'example.com',
|
61
|
+
:resource_name => '/demo',
|
62
|
+
:key1 => '18x 6]8vM;54 *(5: { U1]8 z [ 8',
|
63
|
+
:key2 => '1_ tx7X d < nw 334J702) 7]o}` 0',
|
64
|
+
:challenge => 'Tm[K T2u'
|
65
|
+
)
|
66
|
+
assert_equal req.to_s, "GET /demo HTTP/1.1\x0d\x0a" +
|
67
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
68
|
+
"Connection: Upgrade\x0d\x0a" +
|
69
|
+
"Host: example.com\x0d\x0a" +
|
70
|
+
"Origin: http://example.com\x0d\x0a" +
|
71
|
+
"Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8\x0d\x0a" +
|
72
|
+
"Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0\x0d\x0a" +
|
73
|
+
"Content-Length: 8\x0d\x0a" +
|
74
|
+
"\x0d\x0a" +
|
75
|
+
"Tm[K T2u"
|
76
|
+
assert_equal "fQJ,fN/4F4!~K~MH", req.checksum
|
77
|
+
|
78
|
+
req = LibWebSocket::Request.new(
|
79
|
+
:host => 'example.com',
|
80
|
+
:resource_name => '/demo',
|
81
|
+
:subprotocol => 'sample',
|
82
|
+
:key1 => '18x 6]8vM;54 *(5: { U1]8 z [ 8',
|
83
|
+
:key2 => '1_ tx7X d < nw 334J702) 7]o}` 0',
|
84
|
+
:challenge => 'Tm[K T2u'
|
85
|
+
)
|
86
|
+
assert_equal req.to_s, "GET /demo HTTP/1.1\x0d\x0a" +
|
87
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
88
|
+
"Connection: Upgrade\x0d\x0a" +
|
89
|
+
"Host: example.com\x0d\x0a" +
|
90
|
+
"Origin: http://example.com\x0d\x0a" +
|
91
|
+
"Sec-WebSocket-Protocol: sample\x0d\x0a" +
|
92
|
+
"Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8\x0d\x0a" +
|
93
|
+
"Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0\x0d\x0a" +
|
94
|
+
"Content-Length: 8\x0d\x0a" +
|
95
|
+
"\x0d\x0a" +
|
96
|
+
"Tm[K T2u";
|
97
|
+
assert_equal "fQJ,fN/4F4!~K~MH", req.checksum
|
98
|
+
|
99
|
+
req = LibWebSocket::Request.new(
|
100
|
+
:host => 'example.com',
|
101
|
+
:resource_name => '/demo',
|
102
|
+
:key1 => '55 997',
|
103
|
+
:key2 => '3 3 64 98',
|
104
|
+
:challenge => "\x00\x09\x68\x32\x00\x78\xc7\x10"
|
105
|
+
)
|
106
|
+
assert_equal req.checksum, "\xc4\x15\xc2\xc8\x29\x5c\x94\x8a\x95\xb9\x4d\xec\x5b\x1d\x33\xce"
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_to_s
|
110
|
+
req = LibWebSocket::Request.new(
|
111
|
+
:host => 'example.com',
|
112
|
+
:resource_name => '/demo'
|
113
|
+
)
|
114
|
+
req.to_s
|
115
|
+
assert req.number1
|
116
|
+
assert req.key1
|
117
|
+
assert req.number2
|
118
|
+
assert req.key2
|
119
|
+
assert_equal 8, req.challenge.length
|
120
|
+
assert_equal 16, req.checksum.length
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestRequestCommon < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_parse
|
6
|
+
req = LibWebSocket::Request.new
|
7
|
+
assert !req.done?
|
8
|
+
assert_nil req.parse("foo\x0d\x0a")
|
9
|
+
assert_equal 'error', req.state
|
10
|
+
assert_equal 'Wrong request line', req.error
|
11
|
+
|
12
|
+
req = LibWebSocket::Request.new
|
13
|
+
assert req.parse("GET /demo HTTP/1.1\x0d\x0a")
|
14
|
+
assert req.parse("Upgrade: WebSocket\x0d\x0a")
|
15
|
+
assert req.parse("Connection: Upgrade\x0d\x0a")
|
16
|
+
assert req.parse("Origin: http://example.com\x0d\x0a")
|
17
|
+
assert_nil req.parse("\x0d\x0a")
|
18
|
+
assert_equal 'error', req.state
|
19
|
+
|
20
|
+
req = LibWebSocket::Request.new
|
21
|
+
assert_nil req.parse('x' * (1024 * 10))
|
22
|
+
assert_equal 'error', req.state
|
23
|
+
assert_equal 'Message is too long', req.error
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestResponse75 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_to_s
|
6
|
+
res = LibWebSocket::Response.new
|
7
|
+
res.version = 75
|
8
|
+
res.host = 'example.com'
|
9
|
+
assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
10
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
11
|
+
"Connection: Upgrade\x0d\x0a" +
|
12
|
+
"WebSocket-Origin: http://example.com\x0d\x0a" +
|
13
|
+
"WebSocket-Location: ws://example.com/\x0d\x0a" +
|
14
|
+
"\x0d\x0a"
|
15
|
+
|
16
|
+
res = LibWebSocket::Response.new
|
17
|
+
res.version = 75
|
18
|
+
res.host = 'example.com'
|
19
|
+
res.subprotocol = 'sample'
|
20
|
+
assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
21
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
22
|
+
"Connection: Upgrade\x0d\x0a" +
|
23
|
+
"WebSocket-Protocol: sample\x0d\x0a" +
|
24
|
+
"WebSocket-Origin: http://example.com\x0d\x0a" +
|
25
|
+
"WebSocket-Location: ws://example.com/\x0d\x0a" +
|
26
|
+
"\x0d\x0a";
|
27
|
+
|
28
|
+
res = LibWebSocket::Response.new
|
29
|
+
res.version = 75
|
30
|
+
res.host = 'example.com'
|
31
|
+
res.secure = true
|
32
|
+
assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
33
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
34
|
+
"Connection: Upgrade\x0d\x0a" +
|
35
|
+
"WebSocket-Origin: http://example.com\x0d\x0a" +
|
36
|
+
"WebSocket-Location: wss://example.com/\x0d\x0a" +
|
37
|
+
"\x0d\x0a";
|
38
|
+
|
39
|
+
res = LibWebSocket::Response.new
|
40
|
+
res.version = 75
|
41
|
+
res.host = 'example.com'
|
42
|
+
res.resource_name = '/demo'
|
43
|
+
res.origin = 'file://'
|
44
|
+
res.cookie = {:name => 'foo', :value => 'bar', :path => '/'}
|
45
|
+
|
46
|
+
assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
47
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
48
|
+
"Connection: Upgrade\x0d\x0a" +
|
49
|
+
"WebSocket-Origin: file://\x0d\x0a" +
|
50
|
+
"WebSocket-Location: ws://example.com/demo\x0d\x0a" +
|
51
|
+
"Set-Cookie: foo=bar; Path=/; Version=1\x0d\x0a" +
|
52
|
+
"\x0d\x0a";
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_parse
|
56
|
+
res = LibWebSocket::Response.new
|
57
|
+
res.parse("HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a")
|
58
|
+
res.parse("Upgrade: WebSocket\x0d\x0a")
|
59
|
+
res.parse("Connection: Upgrade\x0d\x0a")
|
60
|
+
res.parse("WebSocket-Protocol: sample\x0d\x0a")
|
61
|
+
res.parse("WebSocket-Origin: file://\x0d\x0a")
|
62
|
+
res.parse("WebSocket-Location: ws://example.com/demo\x0d\x0a")
|
63
|
+
res.parse("\x0d\x0a\x00foo\xff")
|
64
|
+
assert res.done?
|
65
|
+
assert_equal 75, res.version
|
66
|
+
assert_equal 'sample', res.subprotocol
|
67
|
+
|
68
|
+
message = "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
69
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
70
|
+
"Connection: Upgrade\x0d\x0a" +
|
71
|
+
"WebSocket-Origin: file://\x0d\x0a" +
|
72
|
+
"WebSocket-Location: ws://example.com/demo\x0d\x0a" +
|
73
|
+
"\x0d\x0a\x00foo\xff"
|
74
|
+
res = LibWebSocket::Response.new
|
75
|
+
assert res.parse(message)
|
76
|
+
assert res.done?
|
77
|
+
assert_equal 75, res.version
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestResponse76 < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_parse
|
6
|
+
res = LibWebSocket::Response.new
|
7
|
+
assert res.parse("HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a")
|
8
|
+
assert res.parse("Upgrade: WebSocket\x0d\x0a")
|
9
|
+
assert res.parse("Connection: Upgrade\x0d\x0a")
|
10
|
+
assert res.parse("Sec-WebSocket-Origin: file://\x0d\x0a")
|
11
|
+
assert res.parse("Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a")
|
12
|
+
assert res.parse("\x0d\x0a")
|
13
|
+
assert res.parse("0st3Rl&q-2ZU^weu")
|
14
|
+
assert res.done?
|
15
|
+
assert_equal '0st3Rl&q-2ZU^weu', res.checksum
|
16
|
+
assert !res.secure
|
17
|
+
assert_equal 'example.com', res.host
|
18
|
+
assert_equal '/demo', res.resource_name
|
19
|
+
assert_equal 'file://', res.origin
|
20
|
+
|
21
|
+
res = LibWebSocket::Response.new
|
22
|
+
assert res.parse("HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a")
|
23
|
+
assert res.parse("Upgrade: WebSocket\x0d\x0a")
|
24
|
+
assert res.parse("Connection: Upgrade\x0d\x0a")
|
25
|
+
assert res.parse("Sec-WebSocket-Protocol: sample\x0d\x0a")
|
26
|
+
assert res.parse("Sec-WebSocket-Origin: file://\x0d\x0a")
|
27
|
+
assert res.parse("Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a")
|
28
|
+
assert res.parse("\x0d\x0a")
|
29
|
+
assert res.parse("0st3Rl&q-2ZU^weu")
|
30
|
+
assert res.done?
|
31
|
+
assert_equal 'sample', res.subprotocol
|
32
|
+
|
33
|
+
res = LibWebSocket::Response.new
|
34
|
+
message = "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
35
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
36
|
+
"Connection: Upgrade\x0d\x0a"
|
37
|
+
assert res.parse(message)
|
38
|
+
message = "Sec-WebSocket-Origin: file://\x0d\x0a" +
|
39
|
+
"Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a" +
|
40
|
+
"\x0d\x0a" +
|
41
|
+
"0st3Rl&q-2ZU^weu\x00foo\xff"
|
42
|
+
assert res.parse(message)
|
43
|
+
assert res.done?
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_to_s
|
47
|
+
res = LibWebSocket::Response.new(
|
48
|
+
:host => 'example.com',
|
49
|
+
:resource_name => '/demo',
|
50
|
+
:origin => 'file://',
|
51
|
+
:number1 => 777_007_543,
|
52
|
+
:number2 => 114_997_259,
|
53
|
+
:challenge => "\x47\x30\x22\x2D\x5A\x3F\x47\x58"
|
54
|
+
)
|
55
|
+
assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
56
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
57
|
+
"Connection: Upgrade\x0d\x0a" +
|
58
|
+
"Sec-WebSocket-Origin: file://\x0d\x0a" +
|
59
|
+
"Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a" +
|
60
|
+
"\x0d\x0a" +
|
61
|
+
"0st3Rl&q-2ZU^weu"
|
62
|
+
|
63
|
+
res = LibWebSocket::Response.new(
|
64
|
+
:host => 'example.com',
|
65
|
+
:resource_name => '/demo',
|
66
|
+
:origin => 'file://',
|
67
|
+
:subprotocol => 'sample',
|
68
|
+
:number1 => 777_007_543,
|
69
|
+
:number2 => 114_997_259,
|
70
|
+
:challenge => "\x47\x30\x22\x2D\x5A\x3F\x47\x58"
|
71
|
+
);
|
72
|
+
assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
73
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
74
|
+
"Connection: Upgrade\x0d\x0a" +
|
75
|
+
"Sec-WebSocket-Protocol: sample\x0d\x0a" +
|
76
|
+
"Sec-WebSocket-Origin: file://\x0d\x0a" +
|
77
|
+
"Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a" +
|
78
|
+
"\x0d\x0a" +
|
79
|
+
"0st3Rl&q-2ZU^weu"
|
80
|
+
|
81
|
+
res = LibWebSocket::Response.new(
|
82
|
+
:secure => true,
|
83
|
+
:host => 'example.com',
|
84
|
+
:resource_name => '/demo',
|
85
|
+
:origin => 'file://',
|
86
|
+
:number1 => 777_007_543,
|
87
|
+
:number2 => 114_997_259,
|
88
|
+
:challenge => "\x47\x30\x22\x2D\x5A\x3F\x47\x58"
|
89
|
+
)
|
90
|
+
assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
91
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
92
|
+
"Connection: Upgrade\x0d\x0a" +
|
93
|
+
"Sec-WebSocket-Origin: file://\x0d\x0a" +
|
94
|
+
"Sec-WebSocket-Location: wss://example.com/demo\x0d\x0a" +
|
95
|
+
"\x0d\x0a" +
|
96
|
+
"0st3Rl&q-2ZU^weu"
|
97
|
+
|
98
|
+
res = LibWebSocket::Response.new(
|
99
|
+
:host => 'example.com',
|
100
|
+
:resource_name => '/demo',
|
101
|
+
:origin => 'file://',
|
102
|
+
:key1 => "18x 6]8vM;54 *(5: { U1]8 z [ 8",
|
103
|
+
:key2 => "1_ tx7X d < nw 334J702) 7]o}` 0",
|
104
|
+
:challenge => "Tm[K T2u"
|
105
|
+
)
|
106
|
+
assert_equal res.to_s, "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a" +
|
107
|
+
"Upgrade: WebSocket\x0d\x0a" +
|
108
|
+
"Connection: Upgrade\x0d\x0a" +
|
109
|
+
"Sec-WebSocket-Origin: file://\x0d\x0a" +
|
110
|
+
"Sec-WebSocket-Location: ws://example.com/demo\x0d\x0a" +
|
111
|
+
"\x0d\x0a" +
|
112
|
+
"fQJ,fN/4F4!~K~MH"
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestResponseCommon < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_parse
|
6
|
+
res = LibWebSocket::Response.new
|
7
|
+
res.parse("foo\x0d\x0a")
|
8
|
+
assert_equal 'error', res.state
|
9
|
+
assert_equal 'Wrong response line', res.error
|
10
|
+
|
11
|
+
res = LibWebSocket::Response.new
|
12
|
+
assert_nil res.parse('x' * (1024 * 10))
|
13
|
+
assert_equal 'error', res.state
|
14
|
+
assert_equal 'Message is too long', res.error
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestURL < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_parse
|
6
|
+
url = LibWebSocket::URL.new
|
7
|
+
assert url.parse('ws://example.com/')
|
8
|
+
assert !url.secure
|
9
|
+
assert_equal 'example.com', url.host
|
10
|
+
assert_equal '/', url.resource_name
|
11
|
+
|
12
|
+
url = LibWebSocket::URL.new
|
13
|
+
assert url.parse('ws://example.com/demo')
|
14
|
+
assert !url.secure
|
15
|
+
assert_equal 'example.com', url.host
|
16
|
+
assert_equal '/demo', url.resource_name
|
17
|
+
|
18
|
+
url = LibWebSocket::URL.new
|
19
|
+
assert url.parse('ws://example.com:3000')
|
20
|
+
assert !url.secure
|
21
|
+
assert_equal 'example.com', url.host
|
22
|
+
assert_equal '3000', url.port
|
23
|
+
assert_equal '/', url.resource_name
|
24
|
+
|
25
|
+
url = LibWebSocket::URL.new
|
26
|
+
assert url.parse('ws://example.com/demo?foo=bar')
|
27
|
+
assert !url.secure
|
28
|
+
assert_equal 'example.com', url.host
|
29
|
+
assert_equal '/demo', url.resource_name
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_to_s
|
33
|
+
url = LibWebSocket::URL.new(:host => 'foo.com', :secure => true);
|
34
|
+
assert_equal 'wss://foo.com/', url.to_s
|
35
|
+
|
36
|
+
url = LibWebSocket::URL.new(
|
37
|
+
:host => 'foo.com',
|
38
|
+
:resource_name => '/demo'
|
39
|
+
)
|
40
|
+
assert_equal 'ws://foo.com/demo', url.to_s
|
41
|
+
|
42
|
+
url = LibWebSocket::URL.new(
|
43
|
+
:host => 'foo.com',
|
44
|
+
:port => 3000
|
45
|
+
)
|
46
|
+
assert_equal 'ws://foo.com:3000/', url.to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: libwebsocket
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Bernard Potocki
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-05 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Universal Ruby library to handle WebSocket protocol
|
23
|
+
email: bernard.potocki@imanel.org
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README.md
|
30
|
+
files:
|
31
|
+
- README.md
|
32
|
+
- Rakefile
|
33
|
+
- examples/eventmachine_server.rb
|
34
|
+
- examples/plain_client.rb
|
35
|
+
- examples/thin_server.rb
|
36
|
+
- lib/libwebsocket.rb
|
37
|
+
- lib/libwebsocket/cookie.rb
|
38
|
+
- lib/libwebsocket/cookie/request.rb
|
39
|
+
- lib/libwebsocket/cookie/response.rb
|
40
|
+
- lib/libwebsocket/frame.rb
|
41
|
+
- lib/libwebsocket/handshake.rb
|
42
|
+
- lib/libwebsocket/handshake/client.rb
|
43
|
+
- lib/libwebsocket/handshake/server.rb
|
44
|
+
- lib/libwebsocket/message.rb
|
45
|
+
- lib/libwebsocket/request.rb
|
46
|
+
- lib/libwebsocket/response.rb
|
47
|
+
- lib/libwebsocket/stateful.rb
|
48
|
+
- lib/libwebsocket/url.rb
|
49
|
+
- test/libwebsocket/cookie/request.rb
|
50
|
+
- test/libwebsocket/cookie/response.rb
|
51
|
+
- test/libwebsocket/handshake/test_client.rb
|
52
|
+
- test/libwebsocket/handshake/test_server.rb
|
53
|
+
- test/libwebsocket/test_cookie.rb
|
54
|
+
- test/libwebsocket/test_frame.rb
|
55
|
+
- test/libwebsocket/test_message.rb
|
56
|
+
- test/libwebsocket/test_request_75.rb
|
57
|
+
- test/libwebsocket/test_request_76.rb
|
58
|
+
- test/libwebsocket/test_request_common.rb
|
59
|
+
- test/libwebsocket/test_response_75.rb
|
60
|
+
- test/libwebsocket/test_response_76.rb
|
61
|
+
- test/libwebsocket/test_response_common.rb
|
62
|
+
- test/libwebsocket/test_url.rb
|
63
|
+
- test/test_helper.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/imanel/libwebsocket
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Universal Ruby library to handle WebSocket protocol
|
98
|
+
test_files:
|
99
|
+
- test/libwebsocket/cookie/request.rb
|
100
|
+
- test/libwebsocket/cookie/response.rb
|
101
|
+
- test/libwebsocket/handshake/test_client.rb
|
102
|
+
- test/libwebsocket/handshake/test_server.rb
|
103
|
+
- test/libwebsocket/test_cookie.rb
|
104
|
+
- test/libwebsocket/test_frame.rb
|
105
|
+
- test/libwebsocket/test_message.rb
|
106
|
+
- test/libwebsocket/test_request_75.rb
|
107
|
+
- test/libwebsocket/test_request_76.rb
|
108
|
+
- test/libwebsocket/test_request_common.rb
|
109
|
+
- test/libwebsocket/test_response_75.rb
|
110
|
+
- test/libwebsocket/test_response_76.rb
|
111
|
+
- test/libwebsocket/test_response_common.rb
|
112
|
+
- test/libwebsocket/test_url.rb
|
113
|
+
- test/test_helper.rb
|
114
|
+
- examples/eventmachine_server.rb
|
115
|
+
- examples/plain_client.rb
|
116
|
+
- examples/thin_server.rb
|