kinetic_sdk 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/GettingStarted.md +64 -0
- data/README.md +383 -0
- data/bin/console +12 -0
- data/bin/setup +8 -0
- data/gems/kontena-websocket-client-0.1.1/Gemfile +4 -0
- data/gems/kontena-websocket-client-0.1.1/LICENSE +190 -0
- data/gems/kontena-websocket-client-0.1.1/README.md +138 -0
- data/gems/kontena-websocket-client-0.1.1/Rakefile +6 -0
- data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-client.rb +45 -0
- data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark-em.rb +66 -0
- data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.rb +161 -0
- data/gems/kontena-websocket-client-0.1.1/benchmark/benchmark.sh +17 -0
- data/gems/kontena-websocket-client-0.1.1/benchmark/websocket-echo-server.go +207 -0
- data/gems/kontena-websocket-client-0.1.1/examples/websocket-echo-client.rb +80 -0
- data/gems/kontena-websocket-client-0.1.1/kontena-websocket-client.gemspec +24 -0
- data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/connection.rb +119 -0
- data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client/version.rb +13 -0
- data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/client.rb +848 -0
- data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/error.rb +81 -0
- data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/logging.rb +55 -0
- data/gems/kontena-websocket-client-0.1.1/lib/kontena/websocket/openssl_patch.rb +10 -0
- data/gems/kontena-websocket-client-0.1.1/lib/kontena-websocket-client.rb +15 -0
- data/gems/mime-types-3.1/Code-of-Conduct.rdoc +74 -0
- data/gems/mime-types-3.1/Contributing.rdoc +130 -0
- data/gems/mime-types-3.1/History.rdoc +658 -0
- data/gems/mime-types-3.1/Licence.rdoc +25 -0
- data/gems/mime-types-3.1/Manifest.txt +31 -0
- data/gems/mime-types-3.1/README.rdoc +202 -0
- data/gems/mime-types-3.1/Rakefile +254 -0
- data/gems/mime-types-3.1/lib/mime/type/columnar.rb +55 -0
- data/gems/mime-types-3.1/lib/mime/type.rb +573 -0
- data/gems/mime-types-3.1/lib/mime/types/_columnar.rb +135 -0
- data/gems/mime-types-3.1/lib/mime/types/cache.rb +56 -0
- data/gems/mime-types-3.1/lib/mime/types/columnar.rb +1 -0
- data/gems/mime-types-3.1/lib/mime/types/container.rb +30 -0
- data/gems/mime-types-3.1/lib/mime/types/deprecations.rb +32 -0
- data/gems/mime-types-3.1/lib/mime/types/full.rb +17 -0
- data/gems/mime-types-3.1/lib/mime/types/loader.rb +148 -0
- data/gems/mime-types-3.1/lib/mime/types/logger.rb +37 -0
- data/gems/mime-types-3.1/lib/mime/types/registry.rb +81 -0
- data/gems/mime-types-3.1/lib/mime/types.rb +228 -0
- data/gems/mime-types-3.1/lib/mime-types.rb +1 -0
- data/gems/mime-types-3.1/test/bad-fixtures/malformed +9 -0
- data/gems/mime-types-3.1/test/fixture/json.json +1 -0
- data/gems/mime-types-3.1/test/fixture/old-data +9 -0
- data/gems/mime-types-3.1/test/fixture/yaml.yaml +55 -0
- data/gems/mime-types-3.1/test/minitest_helper.rb +13 -0
- data/gems/mime-types-3.1/test/test_mime_type.rb +603 -0
- data/gems/mime-types-3.1/test/test_mime_types.rb +161 -0
- data/gems/mime-types-3.1/test/test_mime_types_cache.rb +109 -0
- data/gems/mime-types-3.1/test/test_mime_types_class.rb +155 -0
- data/gems/mime-types-3.1/test/test_mime_types_lazy.rb +43 -0
- data/gems/mime-types-3.1/test/test_mime_types_loader.rb +32 -0
- data/gems/mime-types-data-3.2016.0521/Code-of-Conduct.md +75 -0
- data/gems/mime-types-data-3.2016.0521/Contributing.md +157 -0
- data/gems/mime-types-data-3.2016.0521/History.md +351 -0
- data/gems/mime-types-data-3.2016.0521/Licence.md +25 -0
- data/gems/mime-types-data-3.2016.0521/Manifest.txt +18 -0
- data/gems/mime-types-data-3.2016.0521/README.md +61 -0
- data/gems/mime-types-data-3.2016.0521/Rakefile +80 -0
- data/gems/mime-types-data-3.2016.0521/data/mime-types.json +1 -0
- data/gems/mime-types-data-3.2016.0521/data/mime.content_type.column +1964 -0
- data/gems/mime-types-data-3.2016.0521/data/mime.docs.column +1964 -0
- data/gems/mime-types-data-3.2016.0521/data/mime.encoding.column +1964 -0
- data/gems/mime-types-data-3.2016.0521/data/mime.flags.column +1964 -0
- data/gems/mime-types-data-3.2016.0521/data/mime.friendly.column +1964 -0
- data/gems/mime-types-data-3.2016.0521/data/mime.pext.column +1964 -0
- data/gems/mime-types-data-3.2016.0521/data/mime.use_instead.column +1964 -0
- data/gems/mime-types-data-3.2016.0521/data/mime.xrefs.column +1964 -0
- data/gems/mime-types-data-3.2016.0521/lib/mime/types/data.rb +21 -0
- data/gems/mime-types-data-3.2016.0521/lib/mime-types-data.rb +3 -0
- data/gems/multipart-post-2.0.0/Gemfile +14 -0
- data/gems/multipart-post-2.0.0/History.txt +60 -0
- data/gems/multipart-post-2.0.0/Manifest.txt +9 -0
- data/gems/multipart-post-2.0.0/README.md +77 -0
- data/gems/multipart-post-2.0.0/Rakefile +9 -0
- data/gems/multipart-post-2.0.0/lib/composite_io.rb +108 -0
- data/gems/multipart-post-2.0.0/lib/multipart_post.rb +9 -0
- data/gems/multipart-post-2.0.0/lib/multipartable.rb +29 -0
- data/gems/multipart-post-2.0.0/lib/net/http/post/multipart.rb +27 -0
- data/gems/multipart-post-2.0.0/lib/parts.rb +96 -0
- data/gems/multipart-post-2.0.0/multipart-post.gemspec +22 -0
- data/gems/multipart-post-2.0.0/test/multibyte.txt +1 -0
- data/gems/multipart-post-2.0.0/test/net/http/post/test_multipart.rb +110 -0
- data/gems/multipart-post-2.0.0/test/test_composite_io.rb +115 -0
- data/gems/multipart-post-2.0.0/test/test_parts.rb +86 -0
- data/gems/parallel-1.12.1/MIT-LICENSE.txt +20 -0
- data/gems/parallel-1.12.1/lib/parallel/processor_count.rb +93 -0
- data/gems/parallel-1.12.1/lib/parallel/version.rb +3 -0
- data/gems/parallel-1.12.1/lib/parallel.rb +500 -0
- data/gems/ruby-progressbar-1.9.0/LICENSE.txt +19 -0
- data/gems/ruby-progressbar-1.9.0/README.md +38 -0
- data/gems/ruby-progressbar-1.9.0/Rakefile +2 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/base.rb +183 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/length.rb +99 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/calculators/running_average.rb +9 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/bar.rb +96 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/percentage.rb +29 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/rate.rb +43 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/time.rb +107 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components/title.rb +13 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/components.rb +5 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/errors/invalid_progress_error.rb +4 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/formatter.rb +27 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/molecule.rb +59 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format/string.rb +36 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/format.rb +3 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/output.rb +68 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/non_tty.rb +47 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/null.rb +33 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/outputs/tty.rb +32 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/progress.rb +118 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements/enumerator.rb +25 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/refinements.rb +1 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/throttle.rb +25 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/time.rb +30 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb +72 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/version.rb +3 -0
- data/gems/ruby-progressbar-1.9.0/lib/ruby-progressbar.rb +18 -0
- data/gems/slugify-1.0.7/README +18 -0
- data/gems/slugify-1.0.7/lib/slugify.rb +1012 -0
- data/gems/slugify-1.0.7/lib/slugify_string.rb +11 -0
- data/gems/slugify-1.0.7/tests/slugify_test.rb +116 -0
- data/gems/slugify-1.0.7/tests/string_slugify_test.rb +23 -0
- data/gems/websocket-driver-0.6.5/CHANGELOG.md +123 -0
- data/gems/websocket-driver-0.6.5/LICENSE.md +22 -0
- data/gems/websocket-driver-0.6.5/README.md +369 -0
- data/gems/websocket-driver-0.6.5/examples/tcp_server.rb +28 -0
- data/gems/websocket-driver-0.6.5/ext/websocket-driver/Makefile +264 -0
- data/gems/websocket-driver-0.6.5/ext/websocket-driver/WebsocketMaskService.java +55 -0
- data/gems/websocket-driver-0.6.5/ext/websocket-driver/extconf.rb +4 -0
- data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.bundle +0 -0
- data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.c +41 -0
- data/gems/websocket-driver-0.6.5/ext/websocket-driver/websocket_mask.o +0 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/client.rb +140 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft75.rb +102 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/draft76.rb +96 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/event_emitter.rb +54 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/headers.rb +45 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/frame.rb +20 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi/message.rb +31 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/hybi.rb +406 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/proxy.rb +68 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/server.rb +80 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver/stream_reader.rb +55 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/driver.rb +199 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/http/headers.rb +112 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/http/request.rb +45 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/http/response.rb +29 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/http.rb +15 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/mask.rb +14 -0
- data/gems/websocket-driver-0.6.5/lib/websocket/websocket_mask.rb +2 -0
- data/gems/websocket-driver-0.6.5/lib/websocket_mask.bundle +0 -0
- data/gems/websocket-driver-0.6.5-java/CHANGELOG.md +123 -0
- data/gems/websocket-driver-0.6.5-java/LICENSE.md +22 -0
- data/gems/websocket-driver-0.6.5-java/README.md +369 -0
- data/gems/websocket-driver-0.6.5-java/examples/tcp_server.rb +28 -0
- data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/WebsocketMaskService.java +55 -0
- data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/extconf.rb +4 -0
- data/gems/websocket-driver-0.6.5-java/ext/websocket-driver/websocket_mask.c +41 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/client.rb +140 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft75.rb +102 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/draft76.rb +96 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/event_emitter.rb +54 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/headers.rb +45 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/frame.rb +20 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi/message.rb +31 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/hybi.rb +406 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/proxy.rb +68 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/server.rb +80 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver/stream_reader.rb +55 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/driver.rb +199 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/http/headers.rb +112 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/http/request.rb +45 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/http/response.rb +29 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/http.rb +15 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/mask.rb +14 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket/websocket_mask.rb +2 -0
- data/gems/websocket-driver-0.6.5-java/lib/websocket_mask.jar +0 -0
- data/gems/websocket-extensions-0.1.3/CHANGELOG.md +15 -0
- data/gems/websocket-extensions-0.1.3/LICENSE.md +20 -0
- data/gems/websocket-extensions-0.1.3/README.md +313 -0
- data/gems/websocket-extensions-0.1.3/lib/websocket/extensions/parser.rb +111 -0
- data/gems/websocket-extensions-0.1.3/lib/websocket/extensions.rb +181 -0
- data/lib/kinetic-sdk.rb +1 -0
- data/lib/kinetic_sdk/bridgehub/bridgehub-sdk.rb +80 -0
- data/lib/kinetic_sdk/bridgehub/lib/access_keys.rb +67 -0
- data/lib/kinetic_sdk/bridgehub/lib/bridge.rb +69 -0
- data/lib/kinetic_sdk/discussions/discussions-sdk.rb +165 -0
- data/lib/kinetic_sdk/discussions/lib/discussions.rb +107 -0
- data/lib/kinetic_sdk/discussions/lib/invitations.rb +120 -0
- data/lib/kinetic_sdk/discussions/lib/messages.rb +190 -0
- data/lib/kinetic_sdk/discussions/lib/meta.rb +14 -0
- data/lib/kinetic_sdk/discussions/lib/participants.rb +64 -0
- data/lib/kinetic_sdk/discussions/lib/related_items.rb +54 -0
- data/lib/kinetic_sdk/discussions/lib/websockets.rb +96 -0
- data/lib/kinetic_sdk/filehub/filehub-sdk.rb +80 -0
- data/lib/kinetic_sdk/filehub/lib/access_keys.rb +67 -0
- data/lib/kinetic_sdk/filehub/lib/filestores.rb +67 -0
- data/lib/kinetic_sdk/request_ce/lib/attribute_definitions.rb +153 -0
- data/lib/kinetic_sdk/request_ce/lib/bridges.rb +66 -0
- data/lib/kinetic_sdk/request_ce/lib/categories.rb +34 -0
- data/lib/kinetic_sdk/request_ce/lib/datastore_form.rb +110 -0
- data/lib/kinetic_sdk/request_ce/lib/datastore_submissions.rb +157 -0
- data/lib/kinetic_sdk/request_ce/lib/form.rb +99 -0
- data/lib/kinetic_sdk/request_ce/lib/form_types.rb +51 -0
- data/lib/kinetic_sdk/request_ce/lib/jwt.rb +55 -0
- data/lib/kinetic_sdk/request_ce/lib/kapp.rb +93 -0
- data/lib/kinetic_sdk/request_ce/lib/meta.rb +14 -0
- data/lib/kinetic_sdk/request_ce/lib/oauth.rb +37 -0
- data/lib/kinetic_sdk/request_ce/lib/security_policy_definitions.rb +157 -0
- data/lib/kinetic_sdk/request_ce/lib/space.rb +89 -0
- data/lib/kinetic_sdk/request_ce/lib/submissions.rb +215 -0
- data/lib/kinetic_sdk/request_ce/lib/system_api.rb +69 -0
- data/lib/kinetic_sdk/request_ce/lib/teams.rb +113 -0
- data/lib/kinetic_sdk/request_ce/lib/users.rb +245 -0
- data/lib/kinetic_sdk/request_ce/lib/webhook_jobs.rb +142 -0
- data/lib/kinetic_sdk/request_ce/lib/webhooks.rb +192 -0
- data/lib/kinetic_sdk/request_ce/request-ce-sdk.rb +153 -0
- data/lib/kinetic_sdk/task/lib/access_keys.rb +94 -0
- data/lib/kinetic_sdk/task/lib/categories.rb +190 -0
- data/lib/kinetic_sdk/task/lib/config.rb +202 -0
- data/lib/kinetic_sdk/task/lib/engine.rb +42 -0
- data/lib/kinetic_sdk/task/lib/environment.rb +14 -0
- data/lib/kinetic_sdk/task/lib/errors.rb +165 -0
- data/lib/kinetic_sdk/task/lib/groups.rb +112 -0
- data/lib/kinetic_sdk/task/lib/handlers.rb +105 -0
- data/lib/kinetic_sdk/task/lib/health.rb +28 -0
- data/lib/kinetic_sdk/task/lib/license.rb +52 -0
- data/lib/kinetic_sdk/task/lib/policy_rules.rb +166 -0
- data/lib/kinetic_sdk/task/lib/setup.rb +56 -0
- data/lib/kinetic_sdk/task/lib/sources.rb +134 -0
- data/lib/kinetic_sdk/task/lib/tasks.rb +17 -0
- data/lib/kinetic_sdk/task/lib/trees.rb +274 -0
- data/lib/kinetic_sdk/task/lib/users.rb +75 -0
- data/lib/kinetic_sdk/task/task-sdk.rb +92 -0
- data/lib/kinetic_sdk/utils/kinetic-http-headers.rb +150 -0
- data/lib/kinetic_sdk/utils/kinetic-http-response.rb +75 -0
- data/lib/kinetic_sdk/utils/kinetic-http.rb +552 -0
- data/lib/kinetic_sdk/utils/logger.rb +70 -0
- data/lib/kinetic_sdk/utils/random.rb +30 -0
- data/lib/kinetic_sdk/version.rb +7 -0
- data/lib/kinetic_sdk.rb +57 -0
- metadata +414 -0
@@ -0,0 +1,199 @@
|
|
1
|
+
# Protocol references:
|
2
|
+
#
|
3
|
+
# * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75
|
4
|
+
# * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
|
5
|
+
# * http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17
|
6
|
+
|
7
|
+
require 'base64'
|
8
|
+
require 'digest/md5'
|
9
|
+
require 'digest/sha1'
|
10
|
+
require 'securerandom'
|
11
|
+
require 'set'
|
12
|
+
require 'stringio'
|
13
|
+
require 'uri'
|
14
|
+
require 'websocket/extensions'
|
15
|
+
|
16
|
+
module WebSocket
|
17
|
+
autoload :HTTP, File.expand_path('../http', __FILE__)
|
18
|
+
|
19
|
+
class Driver
|
20
|
+
|
21
|
+
root = File.expand_path('../driver', __FILE__)
|
22
|
+
|
23
|
+
begin
|
24
|
+
# Load C native extension
|
25
|
+
require 'websocket_mask'
|
26
|
+
rescue LoadError
|
27
|
+
# Fall back to pure-Ruby implementation
|
28
|
+
require 'websocket/mask'
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
if RUBY_PLATFORM =~ /java/
|
33
|
+
require 'jruby'
|
34
|
+
com.jcoglan.websocket.WebsocketMaskService.new.basicLoad(JRuby.runtime)
|
35
|
+
end
|
36
|
+
|
37
|
+
unless Mask.respond_to?(:mask)
|
38
|
+
def Mask.mask(payload, mask)
|
39
|
+
@instance ||= new
|
40
|
+
@instance.mask(payload, mask)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
MAX_LENGTH = 0x3ffffff
|
45
|
+
STATES = [:connecting, :open, :closing, :closed]
|
46
|
+
|
47
|
+
BINARY = 'ASCII-8BIT'
|
48
|
+
UNICODE = 'UTF-8'
|
49
|
+
|
50
|
+
ConnectEvent = Struct.new(nil)
|
51
|
+
OpenEvent = Struct.new(nil)
|
52
|
+
MessageEvent = Struct.new(:data)
|
53
|
+
CloseEvent = Struct.new(:code, :reason)
|
54
|
+
|
55
|
+
ProtocolError = Class.new(StandardError)
|
56
|
+
URIError = Class.new(ArgumentError)
|
57
|
+
ConfigurationError = Class.new(ArgumentError)
|
58
|
+
|
59
|
+
autoload :Client, root + '/client'
|
60
|
+
autoload :Draft75, root + '/draft75'
|
61
|
+
autoload :Draft76, root + '/draft76'
|
62
|
+
autoload :EventEmitter, root + '/event_emitter'
|
63
|
+
autoload :Headers, root + '/headers'
|
64
|
+
autoload :Hybi, root + '/hybi'
|
65
|
+
autoload :Proxy, root + '/proxy'
|
66
|
+
autoload :Server, root + '/server'
|
67
|
+
autoload :StreamReader, root + '/stream_reader'
|
68
|
+
|
69
|
+
include EventEmitter
|
70
|
+
attr_reader :protocol, :ready_state
|
71
|
+
|
72
|
+
def initialize(socket, options = {})
|
73
|
+
super()
|
74
|
+
Driver.validate_options(options, [:max_length, :masking, :require_masking, :protocols])
|
75
|
+
|
76
|
+
@socket = socket
|
77
|
+
@reader = StreamReader.new
|
78
|
+
@options = options
|
79
|
+
@max_length = options[:max_length] || MAX_LENGTH
|
80
|
+
@headers = Headers.new
|
81
|
+
@queue = []
|
82
|
+
@ready_state = 0
|
83
|
+
end
|
84
|
+
|
85
|
+
def state
|
86
|
+
return nil unless @ready_state >= 0
|
87
|
+
STATES[@ready_state]
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_extension(extension)
|
91
|
+
false
|
92
|
+
end
|
93
|
+
|
94
|
+
def set_header(name, value)
|
95
|
+
return false unless @ready_state <= 0
|
96
|
+
@headers[name] = value
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
def start
|
101
|
+
return false unless @ready_state == 0
|
102
|
+
response = handshake_response
|
103
|
+
return false unless response
|
104
|
+
@socket.write(response)
|
105
|
+
open unless @stage == -1
|
106
|
+
true
|
107
|
+
end
|
108
|
+
|
109
|
+
def text(message)
|
110
|
+
message = message.encode(UNICODE) unless message.encoding.name == UNICODE
|
111
|
+
frame(message, :text)
|
112
|
+
end
|
113
|
+
|
114
|
+
def binary(message)
|
115
|
+
false
|
116
|
+
end
|
117
|
+
|
118
|
+
def ping(*args)
|
119
|
+
false
|
120
|
+
end
|
121
|
+
|
122
|
+
def pong(*args)
|
123
|
+
false
|
124
|
+
end
|
125
|
+
|
126
|
+
def close(reason = nil, code = nil)
|
127
|
+
return false unless @ready_state == 1
|
128
|
+
@ready_state = 3
|
129
|
+
emit(:close, CloseEvent.new(nil, nil))
|
130
|
+
true
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def open
|
136
|
+
@ready_state = 1
|
137
|
+
@queue.each { |message| frame(*message) }
|
138
|
+
@queue = []
|
139
|
+
emit(:open, OpenEvent.new)
|
140
|
+
end
|
141
|
+
|
142
|
+
def queue(message)
|
143
|
+
@queue << message
|
144
|
+
true
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.client(socket, options = {})
|
148
|
+
Client.new(socket, options.merge(:masking => true))
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.server(socket, options = {})
|
152
|
+
Server.new(socket, options.merge(:require_masking => true))
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.rack(socket, options = {})
|
156
|
+
env = socket.env
|
157
|
+
if env['HTTP_SEC_WEBSOCKET_VERSION']
|
158
|
+
Hybi.new(socket, options.merge(:require_masking => true))
|
159
|
+
elsif env['HTTP_SEC_WEBSOCKET_KEY1']
|
160
|
+
Draft76.new(socket, options)
|
161
|
+
else
|
162
|
+
Draft75.new(socket, options)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def self.encode(string, encoding = nil)
|
167
|
+
case string
|
168
|
+
when Array then
|
169
|
+
string = string.pack('C*')
|
170
|
+
encoding ||= BINARY
|
171
|
+
when String then
|
172
|
+
encoding ||= UNICODE
|
173
|
+
end
|
174
|
+
unless string.encoding.name == encoding
|
175
|
+
string = string.dup if string.frozen?
|
176
|
+
string.force_encoding(encoding)
|
177
|
+
end
|
178
|
+
string.valid_encoding? ? string : nil
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.validate_options(options, valid_keys)
|
182
|
+
options.keys.each do |key|
|
183
|
+
unless valid_keys.include?(key)
|
184
|
+
raise ConfigurationError, "Unrecognized option: #{key.inspect}"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.websocket?(env)
|
190
|
+
connection = env['HTTP_CONNECTION'] || ''
|
191
|
+
upgrade = env['HTTP_UPGRADE'] || ''
|
192
|
+
|
193
|
+
env['REQUEST_METHOD'] == 'GET' and
|
194
|
+
connection.downcase.split(/ *, */).include?('upgrade') and
|
195
|
+
upgrade.downcase == 'websocket'
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module WebSocket
|
2
|
+
module HTTP
|
3
|
+
|
4
|
+
module Headers
|
5
|
+
MAX_LINE_LENGTH = 4096
|
6
|
+
CR = 0x0D
|
7
|
+
LF = 0x0A
|
8
|
+
|
9
|
+
# RFC 2616 grammar rules:
|
10
|
+
#
|
11
|
+
# CHAR = <any US-ASCII character (octets 0 - 127)>
|
12
|
+
#
|
13
|
+
# CTL = <any US-ASCII control character
|
14
|
+
# (octets 0 - 31) and DEL (127)>
|
15
|
+
#
|
16
|
+
# SP = <US-ASCII SP, space (32)>
|
17
|
+
#
|
18
|
+
# HT = <US-ASCII HT, horizontal-tab (9)>
|
19
|
+
#
|
20
|
+
# token = 1*<any CHAR except CTLs or separators>
|
21
|
+
#
|
22
|
+
# separators = "(" | ")" | "<" | ">" | "@"
|
23
|
+
# | "," | ";" | ":" | "\" | <">
|
24
|
+
# | "/" | "[" | "]" | "?" | "="
|
25
|
+
# | "{" | "}" | SP | HT
|
26
|
+
#
|
27
|
+
# Or, as redefined in RFC 7230:
|
28
|
+
#
|
29
|
+
# token = 1*tchar
|
30
|
+
#
|
31
|
+
# tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
|
32
|
+
# / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
|
33
|
+
# / DIGIT / ALPHA
|
34
|
+
# ; any VCHAR, except delimiters
|
35
|
+
|
36
|
+
HEADER_LINE = /^([!#\$%&'\*\+\-\.\^_`\|~0-9a-z]+):\s*([\x20-\x7e]*?)\s*$/i
|
37
|
+
|
38
|
+
attr_reader :headers
|
39
|
+
|
40
|
+
def initialize
|
41
|
+
@buffer = []
|
42
|
+
@env = {}
|
43
|
+
@headers = {}
|
44
|
+
@stage = 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def complete?
|
48
|
+
@stage == 2
|
49
|
+
end
|
50
|
+
|
51
|
+
def error?
|
52
|
+
@stage == -1
|
53
|
+
end
|
54
|
+
|
55
|
+
def parse(chunk)
|
56
|
+
chunk.each_byte do |octet|
|
57
|
+
if octet == LF and @stage < 2
|
58
|
+
@buffer.pop if @buffer.last == CR
|
59
|
+
if @buffer.empty?
|
60
|
+
complete if @stage == 1
|
61
|
+
else
|
62
|
+
result = case @stage
|
63
|
+
when 0 then start_line(string_buffer)
|
64
|
+
when 1 then header_line(string_buffer)
|
65
|
+
end
|
66
|
+
|
67
|
+
if result
|
68
|
+
@stage = 1
|
69
|
+
else
|
70
|
+
error
|
71
|
+
end
|
72
|
+
end
|
73
|
+
@buffer = []
|
74
|
+
else
|
75
|
+
@buffer << octet if @stage >= 0
|
76
|
+
error if @stage < 2 and @buffer.size > MAX_LINE_LENGTH
|
77
|
+
end
|
78
|
+
end
|
79
|
+
@env['rack.input'] = StringIO.new(string_buffer)
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def complete
|
85
|
+
@stage = 2
|
86
|
+
end
|
87
|
+
|
88
|
+
def error
|
89
|
+
@stage = -1
|
90
|
+
end
|
91
|
+
|
92
|
+
def header_line(line)
|
93
|
+
return false unless parsed = line.scan(HEADER_LINE).first
|
94
|
+
|
95
|
+
key = HTTP.normalize_header(parsed[0])
|
96
|
+
value = parsed[1].strip
|
97
|
+
|
98
|
+
if @headers.has_key?(key)
|
99
|
+
@headers[key] << ', ' << value
|
100
|
+
else
|
101
|
+
@headers[key] = value
|
102
|
+
end
|
103
|
+
true
|
104
|
+
end
|
105
|
+
|
106
|
+
def string_buffer
|
107
|
+
@buffer.pack('C*')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module WebSocket
|
2
|
+
module HTTP
|
3
|
+
|
4
|
+
class Request
|
5
|
+
include Headers
|
6
|
+
|
7
|
+
REQUEST_LINE = /^(OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT) ([\x21-\x7e]+) (HTTP\/[0-9]+\.[0-9]+)$/
|
8
|
+
REQUEST_TARGET = /^(.*?)(\?(.*))?$/
|
9
|
+
RESERVED_HEADERS = %w[content-length content-type]
|
10
|
+
|
11
|
+
attr_reader :env
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def start_line(line)
|
16
|
+
return false unless parsed = line.scan(REQUEST_LINE).first
|
17
|
+
|
18
|
+
target = parsed[1].scan(REQUEST_TARGET).first
|
19
|
+
|
20
|
+
@env = {
|
21
|
+
'REQUEST_METHOD' => parsed[0],
|
22
|
+
'SCRIPT_NAME' => '',
|
23
|
+
'PATH_INFO' => target[0],
|
24
|
+
'QUERY_STRING' => target[2] || ''
|
25
|
+
}
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def complete
|
30
|
+
super
|
31
|
+
@headers.each do |name, value|
|
32
|
+
rack_name = name.upcase.gsub(/-/, '_')
|
33
|
+
rack_name = "HTTP_#{rack_name}" unless RESERVED_HEADERS.include?(name)
|
34
|
+
@env[rack_name] = value
|
35
|
+
end
|
36
|
+
if host = @env['HTTP_HOST']
|
37
|
+
uri = URI.parse("http://#{host}")
|
38
|
+
@env['SERVER_NAME'] = uri.host
|
39
|
+
@env['SERVER_PORT'] = uri.port.to_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module WebSocket
|
2
|
+
module HTTP
|
3
|
+
|
4
|
+
class Response
|
5
|
+
include Headers
|
6
|
+
|
7
|
+
STATUS_LINE = /^(HTTP\/[0-9]+\.[0-9]+) ([0-9]{3}) ([\x20-\x7e]+)$/
|
8
|
+
|
9
|
+
attr_reader :code
|
10
|
+
|
11
|
+
def [](name)
|
12
|
+
@headers[HTTP.normalize_header(name)]
|
13
|
+
end
|
14
|
+
|
15
|
+
def body
|
16
|
+
@buffer.pack('C*')
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def start_line(line)
|
22
|
+
return false unless parsed = line.scan(STATUS_LINE).first
|
23
|
+
@code = parsed[1].to_i
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module WebSocket
|
2
|
+
module HTTP
|
3
|
+
|
4
|
+
root = File.expand_path('../http', __FILE__)
|
5
|
+
|
6
|
+
autoload :Headers, root + '/headers'
|
7
|
+
autoload :Request, root + '/request'
|
8
|
+
autoload :Response, root + '/response'
|
9
|
+
|
10
|
+
def self.normalize_header(name)
|
11
|
+
name.to_s.strip.downcase.gsub(/^http_/, '').gsub(/_/, '-')
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module WebSocket
|
2
|
+
module Mask
|
3
|
+
def self.mask(payload, mask)
|
4
|
+
return payload if mask.nil? || payload.empty?
|
5
|
+
|
6
|
+
payload.tap do |result|
|
7
|
+
payload.bytesize.times do |i|
|
8
|
+
result.setbyte(i, payload.getbyte(i) ^ mask.getbyte(i % 4))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
Binary file
|
@@ -0,0 +1,15 @@
|
|
1
|
+
### 0.1.3 / 2017-11-11
|
2
|
+
|
3
|
+
* Accept extension names and parameters including uppercase letters
|
4
|
+
|
5
|
+
### 0.1.2 / 2015-02-19
|
6
|
+
|
7
|
+
* Make it safe to call `Extensions#close` if the handshake is not complete
|
8
|
+
|
9
|
+
### 0.1.1 / 2014-12-14
|
10
|
+
|
11
|
+
* Explicitly require `strscan` which is not loaded in a vanilla Ruby environment
|
12
|
+
|
13
|
+
### 0.1.0 / 2014-12-13
|
14
|
+
|
15
|
+
* Initial release
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# The MIT license
|
2
|
+
|
3
|
+
Copyright (c) 2014-2017 James Coglan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the 'Software'), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|