libwebsocket 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/examples/eventmachine_server.rb +1 -1
- data/examples/plain_client.rb +1 -1
- data/examples/thin_server.rb +1 -1
- data/lib/libwebsocket.rb +9 -9
- data/lib/libwebsocket/{handshake.rb → opening_handshake.rb} +4 -4
- data/lib/libwebsocket/{handshake → opening_handshake}/client.rb +3 -3
- data/lib/libwebsocket/{handshake → opening_handshake}/server.rb +3 -3
- data/lib/libwebsocket/response.rb +1 -1
- data/libwebsocket.gemspec +90 -0
- data/test/libwebsocket/{handshake → opening_handshake}/test_client.rb +5 -5
- data/test/libwebsocket/{handshake → opening_handshake}/test_server.rb +4 -4
- metadata +11 -10
data/README.md
CHANGED
@@ -5,7 +5,7 @@ be one. It can be used in any server, event loop etc.
|
|
5
5
|
|
6
6
|
## Server handshake
|
7
7
|
|
8
|
-
h = LibWebSocket::
|
8
|
+
h = LibWebSocket::OpeningHandshake::Server.new
|
9
9
|
|
10
10
|
# Parse client request
|
11
11
|
h.parse \<<EOF
|
@@ -34,7 +34,7 @@ be one. It can be used in any server, event loop etc.
|
|
34
34
|
|
35
35
|
## Client handshake
|
36
36
|
|
37
|
-
h = LibWebSocket::
|
37
|
+
h = LibWebSocket::OpeningHandshake::Client.new(url => 'ws://example.com')
|
38
38
|
|
39
39
|
# Create request
|
40
40
|
h.to_s # GET /demo HTTP/1.1
|
@@ -6,7 +6,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../lib/libwebsocket')
|
|
6
6
|
|
7
7
|
module EchoServer
|
8
8
|
def receive_data(data)
|
9
|
-
@hs ||= LibWebSocket::
|
9
|
+
@hs ||= LibWebSocket::OpeningHandshake::Server.new
|
10
10
|
@frame ||= LibWebSocket::Frame.new
|
11
11
|
|
12
12
|
if !@hs.done?
|
data/examples/plain_client.rb
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../lib/libwebsocket')
|
|
4
4
|
class WebSocket
|
5
5
|
|
6
6
|
def initialize(url, params = {})
|
7
|
-
@hs ||= LibWebSocket::
|
7
|
+
@hs ||= LibWebSocket::OpeningHandshake::Client.new(:url => url, :version => params[:version])
|
8
8
|
@frame ||= LibWebSocket::Frame.new
|
9
9
|
|
10
10
|
@socket = TCPSocket.new(@hs.url.host, @hs.url.port || 80)
|
data/examples/thin_server.rb
CHANGED
data/lib/libwebsocket.rb
CHANGED
@@ -3,15 +3,15 @@
|
|
3
3
|
# or clients to provide WebSocket support.
|
4
4
|
module LibWebSocket
|
5
5
|
|
6
|
-
VERSION = '0.0
|
6
|
+
VERSION = '0.1.0' # Version of LibWebSocket
|
7
7
|
|
8
|
-
autoload :Cookie,
|
9
|
-
autoload :Frame,
|
10
|
-
autoload :
|
11
|
-
autoload :Message,
|
12
|
-
autoload :Request,
|
13
|
-
autoload :Response,
|
14
|
-
autoload :Stateful,
|
15
|
-
autoload :URL,
|
8
|
+
autoload :Cookie, "#{File.dirname(__FILE__)}/libwebsocket/cookie"
|
9
|
+
autoload :Frame, "#{File.dirname(__FILE__)}/libwebsocket/frame"
|
10
|
+
autoload :OpeningHandshake, "#{File.dirname(__FILE__)}/libwebsocket/opening_handshake"
|
11
|
+
autoload :Message, "#{File.dirname(__FILE__)}/libwebsocket/message"
|
12
|
+
autoload :Request, "#{File.dirname(__FILE__)}/libwebsocket/request"
|
13
|
+
autoload :Response, "#{File.dirname(__FILE__)}/libwebsocket/response"
|
14
|
+
autoload :Stateful, "#{File.dirname(__FILE__)}/libwebsocket/stateful"
|
15
|
+
autoload :URL, "#{File.dirname(__FILE__)}/libwebsocket/url"
|
16
16
|
|
17
17
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module LibWebSocket
|
2
|
-
# This is a base class for LibWebSocket::
|
3
|
-
class
|
2
|
+
# This is a base class for LibWebSocket::OpeningHandshake::Client and LibWebSocket::OpeningHandshake::Server.
|
3
|
+
class OpeningHandshake
|
4
4
|
|
5
|
-
autoload :Client, "#{File.dirname(__FILE__)}/
|
6
|
-
autoload :Server, "#{File.dirname(__FILE__)}/
|
5
|
+
autoload :Client, "#{File.dirname(__FILE__)}/opening_handshake/client"
|
6
|
+
autoload :Server, "#{File.dirname(__FILE__)}/opening_handshake/server"
|
7
7
|
|
8
8
|
attr_accessor :secure, :error
|
9
9
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module LibWebSocket
|
2
|
-
class
|
2
|
+
class OpeningHandshake
|
3
3
|
# Construct or parse a client WebSocket handshake. This module is written for
|
4
4
|
# convenience, since using request and response directly requires the same code
|
5
5
|
# again and again.
|
6
6
|
#
|
7
7
|
# SYNOPSIS
|
8
8
|
#
|
9
|
-
# h = LibWebSocket::
|
9
|
+
# h = LibWebSocket::OpeningHandshake::Client.new(:url => 'ws://example.com')
|
10
10
|
#
|
11
11
|
# # Create request
|
12
12
|
# h.to_s # GET /demo HTTP/1.1
|
@@ -32,7 +32,7 @@ module LibWebSocket
|
|
32
32
|
#
|
33
33
|
# h.error # Check if there were any errors
|
34
34
|
# h.done? # Returns true
|
35
|
-
class Client <
|
35
|
+
class Client < OpeningHandshake
|
36
36
|
|
37
37
|
attr_accessor :url
|
38
38
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module LibWebSocket
|
2
|
-
class
|
2
|
+
class OpeningHandshake
|
3
3
|
# Construct or parse a server WebSocket handshake. This module is written for
|
4
4
|
# convenience, since using request and response directly requires the same code
|
5
5
|
# again and again.
|
6
6
|
#
|
7
7
|
# SYNOPSIS
|
8
8
|
#
|
9
|
-
# h = LibWebSocket::
|
9
|
+
# h = LibWebSocket::OpeningHandshake::Server.new
|
10
10
|
#
|
11
11
|
# # Parse client request
|
12
12
|
# h.parse \<<EOF
|
@@ -32,7 +32,7 @@ module LibWebSocket
|
|
32
32
|
# # Sec-WebSocket-Location: ws://example.com/demo
|
33
33
|
# #
|
34
34
|
# # fQJ,fN/4F4!~K~MH
|
35
|
-
class Server <
|
35
|
+
class Server < OpeningHandshake
|
36
36
|
|
37
37
|
# Parse client request
|
38
38
|
# @example
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{libwebsocket}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Bernard Potocki"]
|
12
|
+
s.date = %q{2010-12-05}
|
13
|
+
s.description = %q{Universal Ruby library to handle WebSocket protocol}
|
14
|
+
s.email = %q{bernard.potocki@imanel.org}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"examples/eventmachine_server.rb",
|
22
|
+
"examples/plain_client.rb",
|
23
|
+
"examples/thin_server.rb",
|
24
|
+
"lib/libwebsocket.rb",
|
25
|
+
"lib/libwebsocket/cookie.rb",
|
26
|
+
"lib/libwebsocket/cookie/request.rb",
|
27
|
+
"lib/libwebsocket/cookie/response.rb",
|
28
|
+
"lib/libwebsocket/frame.rb",
|
29
|
+
"lib/libwebsocket/message.rb",
|
30
|
+
"lib/libwebsocket/opening_handshake.rb",
|
31
|
+
"lib/libwebsocket/opening_handshake/client.rb",
|
32
|
+
"lib/libwebsocket/opening_handshake/server.rb",
|
33
|
+
"lib/libwebsocket/request.rb",
|
34
|
+
"lib/libwebsocket/response.rb",
|
35
|
+
"lib/libwebsocket/stateful.rb",
|
36
|
+
"lib/libwebsocket/url.rb",
|
37
|
+
"libwebsocket.gemspec",
|
38
|
+
"test/libwebsocket/cookie/request.rb",
|
39
|
+
"test/libwebsocket/cookie/response.rb",
|
40
|
+
"test/libwebsocket/opening_handshake/test_client.rb",
|
41
|
+
"test/libwebsocket/opening_handshake/test_server.rb",
|
42
|
+
"test/libwebsocket/test_cookie.rb",
|
43
|
+
"test/libwebsocket/test_frame.rb",
|
44
|
+
"test/libwebsocket/test_message.rb",
|
45
|
+
"test/libwebsocket/test_request_75.rb",
|
46
|
+
"test/libwebsocket/test_request_76.rb",
|
47
|
+
"test/libwebsocket/test_request_common.rb",
|
48
|
+
"test/libwebsocket/test_response_75.rb",
|
49
|
+
"test/libwebsocket/test_response_76.rb",
|
50
|
+
"test/libwebsocket/test_response_common.rb",
|
51
|
+
"test/libwebsocket/test_url.rb",
|
52
|
+
"test/test_helper.rb"
|
53
|
+
]
|
54
|
+
s.homepage = %q{http://github.com/imanel/libwebsocket}
|
55
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
56
|
+
s.require_paths = ["lib"]
|
57
|
+
s.rubygems_version = %q{1.3.7}
|
58
|
+
s.summary = %q{Universal Ruby library to handle WebSocket protocol}
|
59
|
+
s.test_files = [
|
60
|
+
"test/libwebsocket/cookie/request.rb",
|
61
|
+
"test/libwebsocket/cookie/response.rb",
|
62
|
+
"test/libwebsocket/opening_handshake/test_client.rb",
|
63
|
+
"test/libwebsocket/opening_handshake/test_server.rb",
|
64
|
+
"test/libwebsocket/test_cookie.rb",
|
65
|
+
"test/libwebsocket/test_frame.rb",
|
66
|
+
"test/libwebsocket/test_message.rb",
|
67
|
+
"test/libwebsocket/test_request_75.rb",
|
68
|
+
"test/libwebsocket/test_request_76.rb",
|
69
|
+
"test/libwebsocket/test_request_common.rb",
|
70
|
+
"test/libwebsocket/test_response_75.rb",
|
71
|
+
"test/libwebsocket/test_response_76.rb",
|
72
|
+
"test/libwebsocket/test_response_common.rb",
|
73
|
+
"test/libwebsocket/test_url.rb",
|
74
|
+
"test/test_helper.rb",
|
75
|
+
"examples/eventmachine_server.rb",
|
76
|
+
"examples/plain_client.rb",
|
77
|
+
"examples/thin_server.rb"
|
78
|
+
]
|
79
|
+
|
80
|
+
if s.respond_to? :specification_version then
|
81
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
82
|
+
s.specification_version = 3
|
83
|
+
|
84
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
85
|
+
else
|
86
|
+
end
|
87
|
+
else
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestServerOpeningHandshake < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_to_s
|
6
|
-
h = LibWebSocket::
|
6
|
+
h = LibWebSocket::OpeningHandshake::Client.new
|
7
7
|
h.url = 'ws://example.com/demo'
|
8
8
|
|
9
9
|
# Mocking
|
@@ -21,7 +21,7 @@ class TestServerHandshake < Test::Unit::TestCase
|
|
21
21
|
"Content-Length: 8\x0d\x0a" +
|
22
22
|
"\x0d\x0aTm[K T2u"
|
23
23
|
|
24
|
-
h = LibWebSocket::
|
24
|
+
h = LibWebSocket::OpeningHandshake::Client.new(:url => 'ws://example.com')
|
25
25
|
|
26
26
|
# Mocking
|
27
27
|
h.req.key1 = "18x 6]8vM;54 *(5: { U1]8 z [ 8"
|
@@ -52,11 +52,11 @@ class TestServerHandshake < Test::Unit::TestCase
|
|
52
52
|
assert h.done?
|
53
53
|
|
54
54
|
message = "HTTP/1.1 101 WebSocket Protocol Handshake\x0d\x0a"
|
55
|
-
h = LibWebSocket::
|
55
|
+
h = LibWebSocket::OpeningHandshake::Client.new(:url => 'ws://example.com')
|
56
56
|
assert h.parse(message)
|
57
57
|
assert !h.error
|
58
58
|
|
59
|
-
h = LibWebSocket::
|
59
|
+
h = LibWebSocket::OpeningHandshake::Client.new
|
60
60
|
assert !h.parse("HTTP/1.0 foo bar\x0d\x0a")
|
61
61
|
assert_equal 'Wrong response line', h.error
|
62
62
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TestServerOpeningHandshake < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_parse
|
6
|
-
h = LibWebSocket::
|
6
|
+
h = LibWebSocket::OpeningHandshake::Server.new
|
7
7
|
assert !h.done?
|
8
8
|
assert h.parse('')
|
9
9
|
|
@@ -27,11 +27,11 @@ class TestServerHandshake < Test::Unit::TestCase
|
|
27
27
|
"fQJ,fN/4F4!~K~MH";
|
28
28
|
|
29
29
|
message = "GET /demo HTTP/1.1\x0d\x0a"
|
30
|
-
h = LibWebSocket::
|
30
|
+
h = LibWebSocket::OpeningHandshake::Server.new
|
31
31
|
assert h.parse(message)
|
32
32
|
assert_nil h.error
|
33
33
|
|
34
|
-
h = LibWebSocket::
|
34
|
+
h = LibWebSocket::OpeningHandshake::Server.new
|
35
35
|
assert_nil h.parse("GET /demo\x0d\x0a")
|
36
36
|
assert_equal 'Wrong request line', h.error
|
37
37
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libwebsocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.4
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bernard Potocki
|
@@ -38,18 +38,19 @@ files:
|
|
38
38
|
- lib/libwebsocket/cookie/request.rb
|
39
39
|
- lib/libwebsocket/cookie/response.rb
|
40
40
|
- lib/libwebsocket/frame.rb
|
41
|
-
- lib/libwebsocket/handshake.rb
|
42
|
-
- lib/libwebsocket/handshake/client.rb
|
43
|
-
- lib/libwebsocket/handshake/server.rb
|
44
41
|
- lib/libwebsocket/message.rb
|
42
|
+
- lib/libwebsocket/opening_handshake.rb
|
43
|
+
- lib/libwebsocket/opening_handshake/client.rb
|
44
|
+
- lib/libwebsocket/opening_handshake/server.rb
|
45
45
|
- lib/libwebsocket/request.rb
|
46
46
|
- lib/libwebsocket/response.rb
|
47
47
|
- lib/libwebsocket/stateful.rb
|
48
48
|
- lib/libwebsocket/url.rb
|
49
|
+
- libwebsocket.gemspec
|
49
50
|
- test/libwebsocket/cookie/request.rb
|
50
51
|
- test/libwebsocket/cookie/response.rb
|
51
|
-
- test/libwebsocket/
|
52
|
-
- test/libwebsocket/
|
52
|
+
- test/libwebsocket/opening_handshake/test_client.rb
|
53
|
+
- test/libwebsocket/opening_handshake/test_server.rb
|
53
54
|
- test/libwebsocket/test_cookie.rb
|
54
55
|
- test/libwebsocket/test_frame.rb
|
55
56
|
- test/libwebsocket/test_message.rb
|
@@ -98,8 +99,8 @@ summary: Universal Ruby library to handle WebSocket protocol
|
|
98
99
|
test_files:
|
99
100
|
- test/libwebsocket/cookie/request.rb
|
100
101
|
- test/libwebsocket/cookie/response.rb
|
101
|
-
- test/libwebsocket/
|
102
|
-
- test/libwebsocket/
|
102
|
+
- test/libwebsocket/opening_handshake/test_client.rb
|
103
|
+
- test/libwebsocket/opening_handshake/test_server.rb
|
103
104
|
- test/libwebsocket/test_cookie.rb
|
104
105
|
- test/libwebsocket/test_frame.rb
|
105
106
|
- test/libwebsocket/test_message.rb
|