protocol-websocket 0.7.0 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/protocol/websocket/connection.rb +14 -9
- data/lib/protocol/websocket/frame.rb +8 -3
- data/lib/protocol/websocket/ping_frame.rb +2 -2
- data/lib/protocol/websocket/version.rb +1 -1
- metadata +10 -32
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -19
- data/Gemfile +0 -4
- data/README.md +0 -64
- data/Rakefile +0 -6
- data/protocol-websocket.gemspec +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d2733227a287e2dfb58f393566e6afea44470aba32c7a8eda8bd9a8f25c2d72
|
4
|
+
data.tar.gz: bdd0966fcc837f1314cf2b88e55699f2de57e6d6af36ecbe3bcdf0c12350935a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3fdd8546a648fa96663aafe278499e3a19266d1dfd9d2c68cd6d330f24c8af7d31ee94fd88c632a4bddec85dd56456980bf5a27d02197548279e069eae3d515
|
7
|
+
data.tar.gz: 2b4faa47644b9811dab2d856831176b282c83df85863fad5db5a7b28055b123230ac89ae2e29eb3529843fec12d80ec11f26b2894ca85a2f243eef2d09bf10fb
|
@@ -24,12 +24,8 @@ require 'securerandom'
|
|
24
24
|
module Protocol
|
25
25
|
module WebSocket
|
26
26
|
class Connection
|
27
|
-
# @
|
27
|
+
# @parameter mask [String] 4-byte mask to be used for frames generated by this connection.
|
28
28
|
def initialize(framer, mask: nil)
|
29
|
-
if mask == true
|
30
|
-
mask = SecureRandom.bytes(4)
|
31
|
-
end
|
32
|
-
|
33
29
|
@framer = framer
|
34
30
|
@mask = mask
|
35
31
|
|
@@ -82,6 +78,8 @@ module Protocol
|
|
82
78
|
|
83
79
|
def write_frame(frame)
|
84
80
|
@framer.write_frame(frame)
|
81
|
+
|
82
|
+
return frame
|
85
83
|
end
|
86
84
|
|
87
85
|
def receive_text(frame)
|
@@ -142,10 +140,10 @@ module Protocol
|
|
142
140
|
end
|
143
141
|
end
|
144
142
|
|
145
|
-
def send_ping(data =
|
143
|
+
def send_ping(data = "")
|
146
144
|
if @state != :closed
|
147
145
|
frame = PingFrame.new(mask: @mask)
|
148
|
-
frame.pack(data)
|
146
|
+
frame.pack(data)
|
149
147
|
|
150
148
|
write_frame(frame)
|
151
149
|
else
|
@@ -161,22 +159,29 @@ module Protocol
|
|
161
159
|
|
162
160
|
def receive_ping(frame)
|
163
161
|
if @state != :closed
|
164
|
-
write_frame(frame.reply)
|
162
|
+
write_frame(frame.reply(mask: @mask))
|
165
163
|
else
|
166
164
|
raise ProtocolError, "Cannot receive ping in state #{@state}"
|
167
165
|
end
|
168
166
|
end
|
169
167
|
|
168
|
+
def receive_pong(frame)
|
169
|
+
# Ignore.
|
170
|
+
end
|
171
|
+
|
170
172
|
def receive_frame(frame)
|
171
173
|
warn "Unhandled frame #{frame.inspect}"
|
172
174
|
end
|
173
175
|
|
174
176
|
# @param buffer [String] a unicode or binary string.
|
175
177
|
def write(buffer)
|
178
|
+
# https://tools.ietf.org/html/rfc6455#section-5.6
|
179
|
+
|
180
|
+
# Text: The "Payload data" is text data encoded as UTF-8
|
176
181
|
if buffer.encoding == Encoding::UTF_8
|
177
182
|
send_text(buffer)
|
178
183
|
else
|
179
|
-
|
184
|
+
send_binary(buffer)
|
180
185
|
end
|
181
186
|
end
|
182
187
|
|
@@ -27,8 +27,13 @@ module Protocol
|
|
27
27
|
|
28
28
|
OPCODE = 0
|
29
29
|
|
30
|
-
# @
|
30
|
+
# @parameter length [Integer] The length of the payload, or nil if the header has not been read yet.
|
31
|
+
# @parameter mask [Boolean | String] An optional 4-byte string which is used to mask the payload.
|
31
32
|
def initialize(finished = true, payload = nil, opcode: self.class::OPCODE, mask: false)
|
33
|
+
if mask == true
|
34
|
+
mask = SecureRandom.bytes(4)
|
35
|
+
end
|
36
|
+
|
32
37
|
@finished = finished
|
33
38
|
@opcode = opcode
|
34
39
|
@mask = mask
|
@@ -109,7 +114,7 @@ module Protocol
|
|
109
114
|
end
|
110
115
|
|
111
116
|
def unpack
|
112
|
-
if @mask
|
117
|
+
if @mask and !@payload.empty?
|
113
118
|
data = String.new.b
|
114
119
|
|
115
120
|
for i in 0...@payload.bytesize do
|
@@ -147,7 +152,7 @@ module Protocol
|
|
147
152
|
buffer = stream.read(2) or raise EOFError, "Could not read length!"
|
148
153
|
length = buffer.unpack('n').first
|
149
154
|
elsif length == 127
|
150
|
-
buffer = stream.read(
|
155
|
+
buffer = stream.read(8) or raise EOFError, "Could not read length!"
|
151
156
|
length = buffer.unpack('Q>').first
|
152
157
|
end
|
153
158
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-websocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: protocol-http
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: covered
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '10.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '10.0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: rspec
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,19 +80,12 @@ dependencies:
|
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '3.0'
|
97
|
-
description:
|
83
|
+
description:
|
98
84
|
email:
|
99
|
-
- samuel.williams@oriontransfer.co.nz
|
100
85
|
executables: []
|
101
86
|
extensions: []
|
102
87
|
extra_rdoc_files: []
|
103
88
|
files:
|
104
|
-
- ".gitignore"
|
105
|
-
- ".rspec"
|
106
|
-
- ".travis.yml"
|
107
|
-
- Gemfile
|
108
|
-
- README.md
|
109
|
-
- Rakefile
|
110
89
|
- lib/protocol/websocket.rb
|
111
90
|
- lib/protocol/websocket/binary_frame.rb
|
112
91
|
- lib/protocol/websocket/close_frame.rb
|
@@ -120,12 +99,11 @@ files:
|
|
120
99
|
- lib/protocol/websocket/pong_frame.rb
|
121
100
|
- lib/protocol/websocket/text_frame.rb
|
122
101
|
- lib/protocol/websocket/version.rb
|
123
|
-
- protocol-websocket.gemspec
|
124
102
|
homepage: https://github.com/socketry/protocol-websocket
|
125
103
|
licenses:
|
126
104
|
- MIT
|
127
105
|
metadata: {}
|
128
|
-
post_install_message:
|
106
|
+
post_install_message:
|
129
107
|
rdoc_options: []
|
130
108
|
require_paths:
|
131
109
|
- lib
|
@@ -133,15 +111,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
111
|
requirements:
|
134
112
|
- - ">="
|
135
113
|
- !ruby/object:Gem::Version
|
136
|
-
version:
|
114
|
+
version: 2.5.0
|
137
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
116
|
requirements:
|
139
117
|
- - ">="
|
140
118
|
- !ruby/object:Gem::Version
|
141
119
|
version: '0'
|
142
120
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
144
|
-
signing_key:
|
121
|
+
rubygems_version: 3.1.2
|
122
|
+
signing_key:
|
145
123
|
specification_version: 4
|
146
124
|
summary: A low level implementation of the WebSocket protocol.
|
147
125
|
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: xenial
|
3
|
-
cache: bundler
|
4
|
-
|
5
|
-
matrix:
|
6
|
-
include:
|
7
|
-
- rvm: 2.4
|
8
|
-
- rvm: 2.5
|
9
|
-
- rvm: 2.6
|
10
|
-
- rvm: 2.6
|
11
|
-
env: COVERAGE=PartialSummary,Coveralls
|
12
|
-
- rvm: truffleruby
|
13
|
-
- rvm: jruby-head
|
14
|
-
env: JRUBY_OPTS="--debug -X+O"
|
15
|
-
- rvm: ruby-head
|
16
|
-
allow_failures:
|
17
|
-
- rvm: truffleruby
|
18
|
-
- rvm: ruby-head
|
19
|
-
- rvm: jruby-head
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# Protocol::WebSocket
|
2
|
-
|
3
|
-
Provides a low-level implementation of the WebSocket protocol according to [RFC6455](https://tools.ietf.org/html/rfc6455). It only implements the latest stable version (13).
|
4
|
-
|
5
|
-
[](http://travis-ci.com/socketry/protocol-websocket)
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'protocol-websocket'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install protocol-websocket
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
Here is a basic WebSocket client:
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
stream = # connect to remote system
|
29
|
-
framer = Protocol::WebSocket::Framer.new(stream)
|
30
|
-
|
31
|
-
frame = framer.read_frame
|
32
|
-
```
|
33
|
-
|
34
|
-
## Contributing
|
35
|
-
|
36
|
-
1. Fork it
|
37
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
-
5. Create new Pull Request
|
41
|
-
|
42
|
-
## License
|
43
|
-
|
44
|
-
Released under the MIT license.
|
45
|
-
|
46
|
-
Copyright, 2019, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
47
|
-
|
48
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
49
|
-
of this software and associated documentation files (the "Software"), to deal
|
50
|
-
in the Software without restriction, including without limitation the rights
|
51
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
52
|
-
copies of the Software, and to permit persons to whom the Software is
|
53
|
-
furnished to do so, subject to the following conditions:
|
54
|
-
|
55
|
-
The above copyright notice and this permission notice shall be included in
|
56
|
-
all copies or substantial portions of the Software.
|
57
|
-
|
58
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
59
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
60
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
61
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
62
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
63
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
64
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
data/protocol-websocket.gemspec
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative "lib/protocol/websocket/version"
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = "protocol-websocket"
|
6
|
-
spec.version = Protocol::WebSocket::VERSION
|
7
|
-
spec.authors = ["Samuel Williams"]
|
8
|
-
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
9
|
-
|
10
|
-
spec.summary = "A low level implementation of the WebSocket protocol."
|
11
|
-
spec.homepage = "https://github.com/socketry/protocol-websocket"
|
12
|
-
spec.license = "MIT"
|
13
|
-
|
14
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
15
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
-
end
|
17
|
-
|
18
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_dependency "protocol-http", "~> 0.2"
|
22
|
-
spec.add_dependency "protocol-http1", "~> 0.2"
|
23
|
-
|
24
|
-
spec.add_development_dependency "covered"
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
-
end
|