iodine 0.1.21 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of iodine might be problematic. Click here for more details.

Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -2
  3. data/.travis.yml +23 -2
  4. data/CHANGELOG.md +9 -2
  5. data/README.md +232 -179
  6. data/Rakefile +13 -1
  7. data/bin/config.ru +63 -0
  8. data/bin/console +6 -0
  9. data/bin/echo +42 -32
  10. data/bin/http-hello +62 -0
  11. data/bin/http-playground +124 -0
  12. data/bin/playground +62 -0
  13. data/bin/poc/Gemfile.lock +23 -0
  14. data/bin/poc/README.md +37 -0
  15. data/bin/poc/config.ru +66 -0
  16. data/bin/poc/gemfile +1 -0
  17. data/bin/poc/www/index.html +57 -0
  18. data/bin/raw-rbhttp +35 -0
  19. data/bin/raw_broadcast +66 -0
  20. data/bin/test_with_faye +40 -0
  21. data/bin/ws-broadcast +108 -0
  22. data/bin/ws-echo +108 -0
  23. data/exe/iodine +59 -0
  24. data/ext/iodine/base64.c +264 -0
  25. data/ext/iodine/base64.h +72 -0
  26. data/ext/iodine/bscrypt-common.h +109 -0
  27. data/ext/iodine/bscrypt.h +49 -0
  28. data/ext/iodine/extconf.rb +41 -0
  29. data/ext/iodine/hex.c +123 -0
  30. data/ext/iodine/hex.h +70 -0
  31. data/ext/iodine/http.c +200 -0
  32. data/ext/iodine/http.h +128 -0
  33. data/ext/iodine/http1.c +402 -0
  34. data/ext/iodine/http1.h +56 -0
  35. data/ext/iodine/http1_simple_parser.c +473 -0
  36. data/ext/iodine/http1_simple_parser.h +59 -0
  37. data/ext/iodine/http_request.h +128 -0
  38. data/ext/iodine/http_response.c +1606 -0
  39. data/ext/iodine/http_response.h +393 -0
  40. data/ext/iodine/http_response_http1.h +374 -0
  41. data/ext/iodine/iodine_core.c +641 -0
  42. data/ext/iodine/iodine_core.h +70 -0
  43. data/ext/iodine/iodine_http.c +615 -0
  44. data/ext/iodine/iodine_http.h +19 -0
  45. data/ext/iodine/iodine_websocket.c +430 -0
  46. data/ext/iodine/iodine_websocket.h +21 -0
  47. data/ext/iodine/libasync.c +552 -0
  48. data/ext/iodine/libasync.h +117 -0
  49. data/ext/iodine/libreact.c +347 -0
  50. data/ext/iodine/libreact.h +244 -0
  51. data/ext/iodine/libserver.c +912 -0
  52. data/ext/iodine/libserver.h +435 -0
  53. data/ext/iodine/libsock.c +950 -0
  54. data/ext/iodine/libsock.h +478 -0
  55. data/ext/iodine/misc.c +181 -0
  56. data/ext/iodine/misc.h +76 -0
  57. data/ext/iodine/random.c +193 -0
  58. data/ext/iodine/random.h +48 -0
  59. data/ext/iodine/rb-call.c +127 -0
  60. data/ext/iodine/rb-call.h +60 -0
  61. data/ext/iodine/rb-libasync.h +79 -0
  62. data/ext/iodine/rb-rack-io.c +389 -0
  63. data/ext/iodine/rb-rack-io.h +17 -0
  64. data/ext/iodine/rb-registry.c +213 -0
  65. data/ext/iodine/rb-registry.h +33 -0
  66. data/ext/iodine/sha1.c +359 -0
  67. data/ext/iodine/sha1.h +85 -0
  68. data/ext/iodine/sha2.c +825 -0
  69. data/ext/iodine/sha2.h +138 -0
  70. data/ext/iodine/siphash.c +136 -0
  71. data/ext/iodine/siphash.h +15 -0
  72. data/ext/iodine/spnlock.h +235 -0
  73. data/ext/iodine/websockets.c +696 -0
  74. data/ext/iodine/websockets.h +120 -0
  75. data/ext/iodine/xor-crypt.c +189 -0
  76. data/ext/iodine/xor-crypt.h +107 -0
  77. data/iodine.gemspec +25 -18
  78. data/lib/iodine.rb +57 -58
  79. data/lib/iodine/http.rb +0 -189
  80. data/lib/iodine/protocol.rb +36 -245
  81. data/lib/iodine/version.rb +1 -1
  82. data/lib/rack/handler/iodine.rb +145 -2
  83. metadata +115 -37
  84. data/bin/core_http_test +0 -51
  85. data/bin/em playground +0 -56
  86. data/bin/hello_world +0 -75
  87. data/bin/setup +0 -7
  88. data/lib/iodine/client.rb +0 -5
  89. data/lib/iodine/core.rb +0 -102
  90. data/lib/iodine/core_init.rb +0 -143
  91. data/lib/iodine/http/hpack.rb +0 -553
  92. data/lib/iodine/http/http1.rb +0 -251
  93. data/lib/iodine/http/http2.rb +0 -507
  94. data/lib/iodine/http/rack_support.rb +0 -108
  95. data/lib/iodine/http/request.rb +0 -462
  96. data/lib/iodine/http/response.rb +0 -474
  97. data/lib/iodine/http/session.rb +0 -143
  98. data/lib/iodine/http/websocket_client.rb +0 -335
  99. data/lib/iodine/http/websocket_handler.rb +0 -101
  100. data/lib/iodine/http/websockets.rb +0 -336
  101. data/lib/iodine/io.rb +0 -56
  102. data/lib/iodine/logging.rb +0 -46
  103. data/lib/iodine/settings.rb +0 -158
  104. data/lib/iodine/ssl_connector.rb +0 -48
  105. data/lib/iodine/timers.rb +0 -95
@@ -1,3 +1,3 @@
1
1
  module Iodine
2
- VERSION = "0.1.21"
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1,3 +1,146 @@
1
- require 'iodine/http'
1
+ require 'iodine' unless defined?(::Iodine::VERSION)
2
2
 
3
- ::Rack::Handler.register( 'iodine', 'Iodine::Http::Rack') if defined?(::Rack)
3
+ module Iodine
4
+ # {Iodine::Rack} is an Iodine HTTP and Websocket Rack server bundled with {Iodine} for your convinience.
5
+ module Rack
6
+ # get/set the Rack application.
7
+ def self.app=(val)
8
+ @app = val
9
+ end
10
+
11
+ # get/set the Rack application.
12
+ def self.app
13
+ @app
14
+ end
15
+
16
+ # get/set the HTTP connection timeout property. Defaults to 5. Limited to a maximum of 255. 0 values are silently ignored.
17
+ def self.timeout=(t)
18
+ @timeout = t
19
+ end
20
+
21
+ # get/set the HTTP connection timeout property. Defaults to 5.
22
+ def self.timeout
23
+ @timeout
24
+ end
25
+
26
+ # get/set the Websocket connection timeout property. Defaults to 40 seconds. Limited to a maximum of 255. 0 values are silently ignored.
27
+ def self.ws_timeout=(t)
28
+ @ws_timeout = t
29
+ end
30
+
31
+ # get/set the Websocket connection timeout property. Defaults to 40 seconds. Limited to a maximum of 255. 0 values are silently ignored.
32
+ def self.ws_timeout
33
+ @ws_timeout
34
+ end
35
+
36
+ # get/set the HTTP public folder property. Defaults to 5. Defaults to the incoming argumrnts or `nil`.
37
+ def self.public=(val)
38
+ @public = val
39
+ end
40
+ @public = ARGV[ARGV.index('-www') + 1] if ARGV.index('-www')
41
+
42
+ # get/set the HTTP public folder property. Defaults to 5.
43
+ def self.public
44
+ @public
45
+ end
46
+
47
+ # get/set the maximum HTTP body size for incoming data. Defaults to ~50Mb. 0 values are silently ignored.
48
+ def self.max_body_size=(val)
49
+ @max_body_size = val
50
+ end
51
+
52
+ # get/set the maximum HTTP body size for incoming data. Defaults to ~50Mb.
53
+ def self.max_body_size
54
+ @max_body_size
55
+ end
56
+
57
+ # get/set the maximum Websocket body size for incoming data. Defaults to defaults to ~250KB. 0 values are silently ignored.
58
+ def self.max_msg_size=(val)
59
+ @max_msg_size = val
60
+ end
61
+
62
+ # get/set the maximum Websocket body size for incoming data. Defaults to defaults to ~250KB. 0 values are silently ignored.
63
+ def self.max_msg_size
64
+ @max_msg_size
65
+ end
66
+
67
+ # get/set the HTTP logging value (true / false). Defaults to the incoming argumrnts or `false`.
68
+ def self.log=(val)
69
+ @log = val
70
+ end
71
+
72
+ # get/set the HTTP logging value (true / false). Defaults to the incoming argumrnts or `false`.
73
+ def self.log
74
+ @log
75
+ end
76
+ @log = true if ARGV.index('-v')
77
+ @log = false if ARGV.index('-q')
78
+
79
+ # get/set the HTTP listenning port. Defaults to 3000.
80
+ def self.port=(val)
81
+ @port = val
82
+ end
83
+
84
+ # get/set the HTTP listenning port. Defaults to 3000.
85
+ def self.port
86
+ @port
87
+ end
88
+ @port = ARGV[ARGV.index('-p') + 1] if ARGV.index('-p')
89
+ @port ||= 3000
90
+
91
+ # get/set the HTTP socket binding address. Defaults to `nil` (usually best).
92
+ def self.address=(val)
93
+ @address = val
94
+ end
95
+
96
+ # get/set the HTTP socket binding address. Defaults to `nil` (usually best).
97
+ def self.address
98
+ @address
99
+ end
100
+ @address = nil
101
+
102
+ # Runs a Rack app, as par the Rack handler requirements.
103
+ def self.run(app, options = {})
104
+ # nested applications... is that a thing?
105
+ if @app && @app != app
106
+ old_app = @app
107
+ @app = proc do |env|
108
+ ret = old_app.call(env)
109
+ ret = app.call(env) if !ret.is_a?(Array) || (ret.is_a?(Array) && ret[0].to_i == 404)
110
+ ret
111
+ end
112
+ else
113
+ @app = app
114
+ end
115
+ @port = options[:Port] if options[:Port]
116
+ @port = options[:Address] if options[:Address]
117
+ # provide Websocket features using Rack::Websocket
118
+ Rack.send :remove_const, :Websocket if defined?(Rack::Websocket)
119
+ Rack.const_set :Websocket, ::Iodine::Websocket
120
+ # start Iodine
121
+ Iodine.start
122
+ # remove the Websocket features from Rack::Websocket
123
+ Rack.send :remove_const, :Websocket
124
+ true
125
+ end
126
+ IODINE_RACK_LOADED = true
127
+ end
128
+ end
129
+
130
+ # Iodine::Rack.app = proc { |env| p env; puts env['rack.input'].read(1024).tap { |s| puts "Got data #{s.length} long, #{s[0].ord}, #{s[1].ord} ... #{s[s.length - 2].ord}, #{s[s.length - 1].ord}:" if s }; env['rack.input'].rewind; [404, {}, []] }
131
+
132
+ ENV['RACK_HANDLER'] = 'iodine'
133
+
134
+ # make Iodine the default fallback position for Rack.
135
+ begin
136
+ require 'rack/handler' unless defined?(Rack::Handler)
137
+ Rack::Handler::WEBrick = ::Iodine::Rack # Rack::Handler.get(:iodine)
138
+ rescue Exception
139
+
140
+ end
141
+
142
+ begin
143
+ ::Rack::Handler.register('iodine', 'Iodine::Rack') if defined?(::Rack::Handler)
144
+ rescue Exception
145
+
146
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iodine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,12 +80,13 @@ dependencies:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
- description: " The Iodine v.0.1.X line and API is deprecated and will not be supported
56
- after v. 0.2.0 is released. "
83
+ description: " Iodine - writing C servers in Ruby."
57
84
  email:
58
85
  - Boaz@2be.co.il
59
- executables: []
60
- extensions: []
86
+ executables:
87
+ - iodine
88
+ extensions:
89
+ - ext/iodine/extconf.rb
61
90
  extra_rdoc_files: []
62
91
  files:
63
92
  - ".gitignore"
@@ -67,34 +96,80 @@ files:
67
96
  - LICENSE.txt
68
97
  - README.md
69
98
  - Rakefile
99
+ - bin/config.ru
70
100
  - bin/console
71
- - bin/core_http_test
72
101
  - bin/echo
73
- - bin/em playground
74
- - bin/hello_world
75
- - bin/setup
102
+ - bin/http-hello
103
+ - bin/http-playground
104
+ - bin/playground
105
+ - bin/poc/Gemfile.lock
106
+ - bin/poc/README.md
107
+ - bin/poc/config.ru
108
+ - bin/poc/gemfile
109
+ - bin/poc/www/index.html
110
+ - bin/raw-rbhttp
111
+ - bin/raw_broadcast
112
+ - bin/test_with_faye
113
+ - bin/ws-broadcast
114
+ - bin/ws-echo
115
+ - exe/iodine
116
+ - ext/iodine/base64.c
117
+ - ext/iodine/base64.h
118
+ - ext/iodine/bscrypt-common.h
119
+ - ext/iodine/bscrypt.h
120
+ - ext/iodine/extconf.rb
121
+ - ext/iodine/hex.c
122
+ - ext/iodine/hex.h
123
+ - ext/iodine/http.c
124
+ - ext/iodine/http.h
125
+ - ext/iodine/http1.c
126
+ - ext/iodine/http1.h
127
+ - ext/iodine/http1_simple_parser.c
128
+ - ext/iodine/http1_simple_parser.h
129
+ - ext/iodine/http_request.h
130
+ - ext/iodine/http_response.c
131
+ - ext/iodine/http_response.h
132
+ - ext/iodine/http_response_http1.h
133
+ - ext/iodine/iodine_core.c
134
+ - ext/iodine/iodine_core.h
135
+ - ext/iodine/iodine_http.c
136
+ - ext/iodine/iodine_http.h
137
+ - ext/iodine/iodine_websocket.c
138
+ - ext/iodine/iodine_websocket.h
139
+ - ext/iodine/libasync.c
140
+ - ext/iodine/libasync.h
141
+ - ext/iodine/libreact.c
142
+ - ext/iodine/libreact.h
143
+ - ext/iodine/libserver.c
144
+ - ext/iodine/libserver.h
145
+ - ext/iodine/libsock.c
146
+ - ext/iodine/libsock.h
147
+ - ext/iodine/misc.c
148
+ - ext/iodine/misc.h
149
+ - ext/iodine/random.c
150
+ - ext/iodine/random.h
151
+ - ext/iodine/rb-call.c
152
+ - ext/iodine/rb-call.h
153
+ - ext/iodine/rb-libasync.h
154
+ - ext/iodine/rb-rack-io.c
155
+ - ext/iodine/rb-rack-io.h
156
+ - ext/iodine/rb-registry.c
157
+ - ext/iodine/rb-registry.h
158
+ - ext/iodine/sha1.c
159
+ - ext/iodine/sha1.h
160
+ - ext/iodine/sha2.c
161
+ - ext/iodine/sha2.h
162
+ - ext/iodine/siphash.c
163
+ - ext/iodine/siphash.h
164
+ - ext/iodine/spnlock.h
165
+ - ext/iodine/websockets.c
166
+ - ext/iodine/websockets.h
167
+ - ext/iodine/xor-crypt.c
168
+ - ext/iodine/xor-crypt.h
76
169
  - iodine.gemspec
77
170
  - lib/iodine.rb
78
- - lib/iodine/client.rb
79
- - lib/iodine/core.rb
80
- - lib/iodine/core_init.rb
81
171
  - lib/iodine/http.rb
82
- - lib/iodine/http/hpack.rb
83
- - lib/iodine/http/http1.rb
84
- - lib/iodine/http/http2.rb
85
- - lib/iodine/http/rack_support.rb
86
- - lib/iodine/http/request.rb
87
- - lib/iodine/http/response.rb
88
- - lib/iodine/http/session.rb
89
- - lib/iodine/http/websocket_client.rb
90
- - lib/iodine/http/websocket_handler.rb
91
- - lib/iodine/http/websockets.rb
92
- - lib/iodine/io.rb
93
- - lib/iodine/logging.rb
94
172
  - lib/iodine/protocol.rb
95
- - lib/iodine/settings.rb
96
- - lib/iodine/ssl_connector.rb
97
- - lib/iodine/timers.rb
98
173
  - lib/iodine/version.rb
99
174
  - lib/rack/handler/iodine.rb
100
175
  homepage: https://github.com/boazsegev/iodine
@@ -103,28 +178,31 @@ licenses:
103
178
  metadata:
104
179
  allowed_push_host: https://rubygems.org
105
180
  post_install_message: |-
106
- The Iodine 0.1.x API is now deprecated.
107
- Version 0.2.x will include a drastic change and it WILL break existing code.
108
- DON'T UPGRADE BEYOND THIS POINT UNLESS YOU'RE PREPARED FOR A HUGE CANGE.
109
- Future version of Iodine will be written in C and require a Linux/Unix machine.
181
+ ** WARNING!
182
+ Iodine 0.2.0 is NOT an upgrade - it's a total rewrite, it's written in C specifically for Ruby MRI.
183
+
184
+ If your application was using Iodine 0.1.x, it might not work after this "upgrade".
110
185
  rdoc_options: []
111
186
  require_paths:
112
187
  - lib
188
+ - ext
113
189
  required_ruby_version: !ruby/object:Gem::Requirement
114
190
  requirements:
115
191
  - - ">="
116
192
  - !ruby/object:Gem::Version
117
- version: '0'
193
+ version: 2.2.2
118
194
  required_rubygems_version: !ruby/object:Gem::Requirement
119
195
  requirements:
120
196
  - - ">="
121
197
  - !ruby/object:Gem::Version
122
198
  version: '0'
123
- requirements: []
199
+ requirements:
200
+ - 'A Unix based system, i.e.: Linux / OS X / BSD.'
201
+ - An updated C compiler, with support for C11 (i.e. gcc 4.9 or later).
202
+ - Ruby >= 2.2.2
124
203
  rubyforge_project:
125
- rubygems_version: 2.4.5.1
204
+ rubygems_version: 2.5.1
126
205
  signing_key:
127
206
  specification_version: 4
128
- summary: The Iodine v.0.1.X line and API is deprecated and will not be supported after
129
- v. 0.2.0 is released.
207
+ summary: Iodine - writing C servers in Ruby.
130
208
  test_files: []
data/bin/core_http_test DELETED
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pathname'
4
- Root ||= Pathname.new(File.dirname(__FILE__)).expand_path
5
- Dir.chdir Root.join('..').to_s
6
-
7
- require "bundler/setup"
8
- require "iodine"
9
- require 'stringio'
10
-
11
- # ab -n 10000 -c 200 -k http://127.0.0.1:3000/
12
- # ab -n 10000 -c 200 -k http://localhost:3000/
13
- # ~/ruby/wrk/wrk -c400 -d10 -t12 http://localhost:3000/
14
-
15
- class MiniServer < Iodine::Protocol
16
- def on_open
17
- @headers = {}
18
- set_timeout 1
19
- end
20
-
21
- def on_message data
22
- data = ::StringIO.new data
23
- l = nil
24
- headers = @headers
25
- while (l = data.gets)
26
- unless l =~ /^[\r]?\n/
27
- if l.include? ':'
28
- l = l.strip.downcase.split(':', 2)
29
- headers[l[0]] = l[1]
30
- else
31
- headers[:method], headers[:query], headers[:version] = l.strip.split(/[\s]+/, 3)
32
- end
33
- next
34
- end
35
- if headers['connection'] =~ /keep/i || headers[:version] =~ /1\.1/
36
- write "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 12\r\nConnection: keep-alive\r\nKeep-Alive: 5\r\n\r\nhello world\n"
37
- else
38
- write "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 12\r\nConnection: close\r\n\r\nhello world\n"
39
- close
40
- end
41
- headers.clear
42
- end
43
- end
44
-
45
- end
46
-
47
- Iodine.threads = 1
48
- # Iodine.ssl = 1
49
- Iodine.protocol = MiniServer
50
-
51
-
data/bin/em playground DELETED
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #encoding: UTF-8
3
-
4
- require 'eventmachine'
5
- require 'stringio'
6
-
7
-
8
- module MiniServer
9
- def post_init
10
- comm_inactivity_timeout = 5
11
- @headers = {}
12
- # start_tls :private_key_file => 'server.key', :cert_chain_file => 'server.crt', :verify_peer => false
13
- end
14
-
15
- def receive_data data
16
- # EventMachine.defer do
17
- data = ::StringIO.new data
18
- l = nil
19
- headers = @headers
20
- while (l = data.gets)
21
- unless l =~ /^[\r]?\n/
22
- if l.include? ':'
23
- l = l.strip.downcase.split(':', 2)
24
- headers[l[0]] = l[1]
25
- else
26
- headers[:method], headers[:query], headers[:version] = l.split(/[\s]+/, 3)
27
- end
28
- next
29
- end
30
- if headers['connection'] =~ /keep/i || headers[:version] =~ /1\.1/
31
- send_data "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 12\r\nConnection: keep-alive\r\nKeep-Alive: 5\r\n\r\nhello world\n"
32
- else
33
- send_data "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 12\r\nConnection: close\r\n\r\nhello world\n"
34
- close_connection true
35
- end
36
- headers.clear
37
- end
38
- data.string.clear
39
- # end
40
- end
41
-
42
- def unbind
43
- end
44
- end
45
-
46
- # Note that this will block current thread.
47
- EventMachine.run {
48
- trap("TERM") { EventMachine.stop_event_loop }
49
- trap("INT") { EventMachine.stop_event_loop }
50
- EventMachine.start_server "127.0.0.1", 3000, MiniServer
51
- }
52
-
53
-
54
- # ab -n 10000 -c 200 -k http://127.0.0.1:3000/ctrl
55
- # ~/ruby/wrk/wrk -c400 -d10 -t12 http://localhost:3000/ctrl
56
-