iodine 0.7.60 → 0.8.0

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.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +15 -0
  3. data/.rspec +1 -0
  4. data/.yardopts +1 -3
  5. data/CHANGELOG.md +132 -12
  6. data/Gemfile +5 -7
  7. data/LICENSE.txt +1 -1
  8. data/README.md +147 -671
  9. data/Rakefile +9 -16
  10. data/examples/chatroom.nru +9 -0
  11. data/examples/client +74 -0
  12. data/examples/config-hello.nru +9 -0
  13. data/examples/config-hello.ru +11 -0
  14. data/examples/config-hijack.ru +13 -0
  15. data/examples/config-shootout.ru +43 -0
  16. data/examples/config.nru +120 -0
  17. data/examples/config.rb +37 -0
  18. data/examples/config.ru +42 -53
  19. data/examples/fake +24 -0
  20. data/examples/hello_neorack +137 -0
  21. data/examples/routes.nru +29 -0
  22. data/examples/routes.ru +42 -0
  23. data/exe/iodine +218 -258
  24. data/ext/iodine/extconf.rb +27 -100
  25. data/ext/iodine/fio-stl.h +128336 -0
  26. data/ext/iodine/fio-stl.md +26396 -0
  27. data/ext/iodine/iodine.c +213 -1393
  28. data/ext/iodine/iodine.h +250 -55
  29. data/ext/iodine/iodine_arg_helper.h +329 -0
  30. data/ext/iodine/iodine_caller.h +234 -25
  31. data/ext/iodine/iodine_cli.h +434 -0
  32. data/ext/iodine/iodine_compression.h +312 -0
  33. data/ext/iodine/iodine_connection.h +3484 -34
  34. data/ext/iodine/iodine_core.h +363 -0
  35. data/ext/iodine/iodine_crypto.h +1441 -0
  36. data/ext/iodine/iodine_defer.h +225 -4
  37. data/ext/iodine/iodine_json.h +738 -4
  38. data/ext/iodine/iodine_listener.h +263 -0
  39. data/ext/iodine/iodine_log.h +297 -0
  40. data/ext/iodine/iodine_minimap.h +543 -0
  41. data/ext/iodine/iodine_mustache.h +461 -4
  42. data/ext/iodine/iodine_pubsub_eng.h +729 -0
  43. data/ext/iodine/iodine_pubsub_history.h +547 -0
  44. data/ext/iodine/iodine_pubsub_msg.h +228 -0
  45. data/ext/iodine/iodine_redis.h +322 -0
  46. data/ext/iodine/iodine_store.h +418 -16
  47. data/ext/iodine/iodine_threads.h +279 -0
  48. data/ext/iodine/iodine_tls.h +515 -6
  49. data/ext/iodine/iodine_utils.h +923 -0
  50. data/iodine.gemspec +37 -42
  51. data/lib/iodine/benchmark.rb +1690 -0
  52. data/lib/iodine/documentation.rb +3085 -0
  53. data/lib/iodine/version.rb +17 -1
  54. data/lib/iodine.rb +54 -255
  55. data/logo.svg +36 -0
  56. data/mustache.md +55 -0
  57. data/sig/iodine.rbs +4 -0
  58. metadata +58 -184
  59. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  60. data/.github/workflows/ruby.yml +0 -42
  61. data/.gitignore +0 -21
  62. data/LIMITS.md +0 -41
  63. data/SPEC-PubSub-Draft.md +0 -159
  64. data/SPEC-WebSocket-Draft.md +0 -239
  65. data/bin/console +0 -22
  66. data/bin/info.md +0 -353
  67. data/bin/mustache_bench.rb +0 -100
  68. data/bin/poc/Gemfile.lock +0 -23
  69. data/bin/poc/README.md +0 -37
  70. data/bin/poc/config.ru +0 -66
  71. data/bin/poc/gemfile +0 -1
  72. data/bin/poc/www/index.html +0 -57
  73. data/examples/async_task.ru +0 -92
  74. data/examples/bates/README.md +0 -3
  75. data/examples/bates/config.ru +0 -342
  76. data/examples/bates/david+bold.pdf +0 -0
  77. data/examples/bates/public/drop-pdf.png +0 -0
  78. data/examples/bates/public/index.html +0 -600
  79. data/examples/echo.ru +0 -59
  80. data/examples/etag.ru +0 -16
  81. data/examples/hello.ru +0 -29
  82. data/examples/pubsub_engine.ru +0 -81
  83. data/examples/rack3.ru +0 -12
  84. data/examples/redis.ru +0 -70
  85. data/examples/shootout.ru +0 -73
  86. data/examples/sub-protocols.ru +0 -90
  87. data/examples/tcp_client.rb +0 -66
  88. data/examples/x-sendfile.ru +0 -14
  89. data/ext/iodine/fio.c +0 -11995
  90. data/ext/iodine/fio.h +0 -6371
  91. data/ext/iodine/fio_cli.c +0 -431
  92. data/ext/iodine/fio_cli.h +0 -189
  93. data/ext/iodine/fio_json_parser.h +0 -688
  94. data/ext/iodine/fio_siphash.c +0 -157
  95. data/ext/iodine/fio_siphash.h +0 -37
  96. data/ext/iodine/fio_tls.h +0 -129
  97. data/ext/iodine/fio_tls_missing.c +0 -649
  98. data/ext/iodine/fio_tls_openssl.c +0 -1106
  99. data/ext/iodine/fio_tmpfile.h +0 -50
  100. data/ext/iodine/fiobj.h +0 -44
  101. data/ext/iodine/fiobj4fio.h +0 -21
  102. data/ext/iodine/fiobj_ary.c +0 -333
  103. data/ext/iodine/fiobj_ary.h +0 -139
  104. data/ext/iodine/fiobj_data.c +0 -1187
  105. data/ext/iodine/fiobj_data.h +0 -167
  106. data/ext/iodine/fiobj_hash.c +0 -409
  107. data/ext/iodine/fiobj_hash.h +0 -176
  108. data/ext/iodine/fiobj_json.c +0 -622
  109. data/ext/iodine/fiobj_json.h +0 -68
  110. data/ext/iodine/fiobj_mem.h +0 -71
  111. data/ext/iodine/fiobj_mustache.c +0 -317
  112. data/ext/iodine/fiobj_mustache.h +0 -62
  113. data/ext/iodine/fiobj_numbers.c +0 -344
  114. data/ext/iodine/fiobj_numbers.h +0 -127
  115. data/ext/iodine/fiobj_str.c +0 -433
  116. data/ext/iodine/fiobj_str.h +0 -172
  117. data/ext/iodine/fiobject.c +0 -620
  118. data/ext/iodine/fiobject.h +0 -655
  119. data/ext/iodine/hpack.h +0 -1923
  120. data/ext/iodine/http.c +0 -2743
  121. data/ext/iodine/http.h +0 -1002
  122. data/ext/iodine/http1.c +0 -910
  123. data/ext/iodine/http1.h +0 -29
  124. data/ext/iodine/http1_parser.h +0 -878
  125. data/ext/iodine/http_internal.c +0 -1279
  126. data/ext/iodine/http_internal.h +0 -237
  127. data/ext/iodine/http_mime_parser.h +0 -350
  128. data/ext/iodine/iodine_caller.c +0 -230
  129. data/ext/iodine/iodine_connection.c +0 -941
  130. data/ext/iodine/iodine_defer.c +0 -420
  131. data/ext/iodine/iodine_fiobj2rb.h +0 -120
  132. data/ext/iodine/iodine_helpers.c +0 -282
  133. data/ext/iodine/iodine_helpers.h +0 -12
  134. data/ext/iodine/iodine_http.c +0 -1181
  135. data/ext/iodine/iodine_http.h +0 -23
  136. data/ext/iodine/iodine_json.c +0 -302
  137. data/ext/iodine/iodine_mustache.c +0 -567
  138. data/ext/iodine/iodine_pubsub.c +0 -580
  139. data/ext/iodine/iodine_pubsub.h +0 -26
  140. data/ext/iodine/iodine_rack_io.c +0 -273
  141. data/ext/iodine/iodine_rack_io.h +0 -20
  142. data/ext/iodine/iodine_store.c +0 -148
  143. data/ext/iodine/iodine_tcp.c +0 -346
  144. data/ext/iodine/iodine_tcp.h +0 -13
  145. data/ext/iodine/iodine_tls.c +0 -261
  146. data/ext/iodine/mustache_parser.h +0 -1546
  147. data/ext/iodine/redis_engine.c +0 -957
  148. data/ext/iodine/redis_engine.h +0 -79
  149. data/ext/iodine/resp_parser.h +0 -317
  150. data/ext/iodine/websocket_parser.h +0 -506
  151. data/ext/iodine/websockets.c +0 -743
  152. data/ext/iodine/websockets.h +0 -185
  153. data/lib/iodine/connection.rb +0 -61
  154. data/lib/iodine/json.rb +0 -42
  155. data/lib/iodine/mustache.rb +0 -113
  156. data/lib/iodine/pubsub.rb +0 -55
  157. data/lib/iodine/rack_utils.rb +0 -43
  158. data/lib/iodine/tls.rb +0 -16
  159. data/lib/rack/handler/iodine.rb +0 -33
  160. data/logo.png +0 -0
@@ -1,282 +0,0 @@
1
- /*
2
- Copyright: Boaz segev, 2016-2017
3
- License: MIT
4
-
5
- Feel free to copy, use and enjoy according to the license provided.
6
- */
7
- #include "iodine.h"
8
-
9
- #include "http.h"
10
- #include <ruby/encoding.h>
11
-
12
- /*
13
- Add all sorts of useless stuff here.
14
- */
15
-
16
- static ID iodine_to_i_func_id;
17
- static rb_encoding *IodineUTF8Encoding;
18
-
19
- /* *****************************************************************************
20
- URL Decoding
21
- ***************************************************************************** */
22
- /**
23
- Decodes a URL encoded String in place.
24
-
25
- Raises an exception on error... but this might result in a partially decoded
26
- String.
27
- */
28
- static VALUE url_decode_inplace(VALUE self, VALUE str) {
29
- Check_Type(str, T_STRING);
30
- ssize_t len =
31
- http_decode_url(RSTRING_PTR(str), RSTRING_PTR(str), RSTRING_LEN(str));
32
- if (len < 0)
33
- rb_raise(rb_eRuntimeError, "Malformed URL string - couldn't decode (String "
34
- "might have been partially altered).");
35
- rb_str_set_len(str, len);
36
- return str;
37
- (void)self;
38
- }
39
-
40
- /**
41
- Decodes a URL encoded String, returning a new String with the decoded data.
42
- */
43
- static VALUE url_decode(VALUE self, VALUE str) {
44
- Check_Type(str, T_STRING);
45
- VALUE str2 = rb_str_buf_new(RSTRING_LEN(str));
46
- ssize_t len =
47
- http_decode_url(RSTRING_PTR(str2), RSTRING_PTR(str), RSTRING_LEN(str));
48
- if (len < 0)
49
- rb_raise(rb_eRuntimeError, "Malformed URL string - couldn't decode.");
50
- rb_str_set_len(str2, len);
51
- return str2;
52
- (void)self;
53
- }
54
-
55
- /**
56
- Decodes a percent encoded String (normally the "path" of a request), editing the
57
- String in place.
58
-
59
- Raises an exception on error... but this might result in a partially decoded
60
- String.
61
- */
62
- static VALUE path_decode_inplace(VALUE self, VALUE str) {
63
- Check_Type(str, T_STRING);
64
- ssize_t len =
65
- http_decode_path(RSTRING_PTR(str), RSTRING_PTR(str), RSTRING_LEN(str));
66
- if (len < 0)
67
- rb_raise(rb_eRuntimeError,
68
- "Malformed URL path string - couldn't decode (String "
69
- "might have been partially altered).");
70
- rb_str_set_len(str, len);
71
- return str;
72
- (void)self;
73
- }
74
-
75
- /**
76
- Decodes a percent encoded String (normally the "path" of a request), returning a
77
- new String with the decoded data.
78
- */
79
- static VALUE path_decode(VALUE self, VALUE str) {
80
- Check_Type(str, T_STRING);
81
- VALUE str2 = rb_str_buf_new(RSTRING_LEN(str));
82
- ssize_t len =
83
- http_decode_path(RSTRING_PTR(str2), RSTRING_PTR(str), RSTRING_LEN(str));
84
- if (len < 0)
85
- rb_raise(rb_eRuntimeError, "Malformed URL path string - couldn't decode.");
86
- rb_str_set_len(str2, len);
87
- return str2;
88
- (void)self;
89
- }
90
-
91
- /**
92
- Decodes a URL encoded String, returning a new String with the decoded data.
93
-
94
- This variation matches the Rack::Utils.unescape signature by accepting and
95
- mostly ignoring an optional Encoding argument.
96
- */
97
- static VALUE unescape(int argc, VALUE *argv, VALUE self) {
98
- if (argc < 1 || argc > 2)
99
- rb_raise(rb_eArgError,
100
- "wrong number of arguments (given %d, expected 1..2).", argc);
101
- VALUE str = argv[0];
102
- Check_Type(str, T_STRING);
103
- VALUE str2 = rb_str_buf_new(RSTRING_LEN(str));
104
- ssize_t len =
105
- http_decode_url(RSTRING_PTR(str2), RSTRING_PTR(str), RSTRING_LEN(str));
106
- if (len < 0)
107
- rb_raise(rb_eRuntimeError, "Malformed URL path string - couldn't decode.");
108
- rb_str_set_len(str2, len);
109
- rb_encoding *enc = IodineUTF8Encoding;
110
- if (argc == 2 && argv[1] != Qnil && argv[1] != Qfalse) {
111
- enc = rb_enc_get(argv[1]);
112
- if (!enc)
113
- enc = IodineUTF8Encoding;
114
- }
115
- rb_enc_associate(str2, enc);
116
- return str2;
117
- (void)self;
118
- }
119
-
120
- /* *****************************************************************************
121
- HTTP Dates
122
- ***************************************************************************** */
123
-
124
- /**
125
- Takes an optional Integer for Unix Time and returns a faster (though less
126
- localized) HTTP Date formatted String.
127
-
128
-
129
- Iodine::Rack.time2str => "Sun, 11 Jun 2017 06:14:08 GMT"
130
-
131
- Iodine::Rack.time2str(Time.now.to_i) => "Wed, 15 Nov 1995 06:25:24 GMT"
132
-
133
- Since Iodine uses time caching within it's reactor, using the default value
134
- (now) will be faster than providing an explicit time using `Time.now.to_i`.
135
-
136
- */
137
- static VALUE date_str(int argc, VALUE *argv, VALUE self) {
138
- if (argc > 1)
139
- rb_raise(rb_eArgError,
140
- "wrong number of arguments (given %d, expected 0..1).", argc);
141
- time_t last_tick;
142
- if (argc) {
143
- if (TYPE(argv[0]) != T_FIXNUM)
144
- argv[0] = rb_funcallv(argv[0], iodine_to_i_func_id, 0, NULL);
145
- Check_Type(argv[0], T_FIXNUM);
146
- last_tick =
147
- FIX2ULONG(argv[0]) ? FIX2ULONG(argv[0]) : fio_last_tick().tv_sec;
148
- } else
149
- last_tick = fio_last_tick().tv_sec;
150
- VALUE str = rb_str_buf_new(32);
151
- struct tm tm;
152
-
153
- http_gmtime(last_tick, &tm);
154
- size_t len = http_date2str(RSTRING_PTR(str), &tm);
155
- rb_str_set_len(str, len);
156
- return str;
157
- (void)self;
158
- }
159
-
160
- /**
161
- Takes `time` and returns a faster (though less localized) HTTP Date formatted
162
- String.
163
-
164
-
165
- Iodine::Rack.rfc2822(Time.now) => "Sun, 11 Jun 2017 06:14:08 -0000"
166
-
167
- Iodine::Rack.rfc2822(0) => "Sun, 11 Jun 2017 06:14:08 -0000"
168
-
169
- Since Iodine uses time caching within it's reactor, using the default value
170
- (by passing 0) will be faster than providing an explicit time using `Time.now`.
171
- */
172
- static VALUE iodine_rfc2822(VALUE self, VALUE rtm) {
173
- time_t last_tick;
174
- rtm = rb_funcallv(rtm, iodine_to_i_func_id, 0, NULL);
175
- last_tick = FIX2ULONG(rtm) ? FIX2ULONG(rtm) : fio_last_tick().tv_sec;
176
- VALUE str = rb_str_buf_new(34);
177
- struct tm tm;
178
-
179
- http_gmtime(last_tick, &tm);
180
- size_t len = http_date2rfc2822(RSTRING_PTR(str), &tm);
181
- rb_str_set_len(str, len);
182
- return str;
183
- (void)self;
184
- }
185
-
186
- /**
187
- Takes `time` and returns a faster (though less localized) HTTP Date formatted
188
- String.
189
-
190
-
191
- Iodine::Rack.rfc2109(Time.now) => "Sun, 11-Jun-2017 06:14:08 GMT"
192
-
193
- Iodine::Rack.rfc2109(0) => "Sun, 11-Jun-2017 06:14:08 GMT"
194
-
195
- Since Iodine uses time caching within it's reactor, using the default value
196
- (by passing 0) will be faster than providing an explicit time using `Time.now`.
197
- */
198
- static VALUE iodine_rfc2109(VALUE self, VALUE rtm) {
199
- time_t last_tick;
200
- rtm = rb_funcallv(rtm, iodine_to_i_func_id, 0, NULL);
201
- last_tick = FIX2ULONG(rtm) ? FIX2ULONG(rtm) : fio_last_tick().tv_sec;
202
- VALUE str = rb_str_buf_new(32);
203
- struct tm tm;
204
-
205
- http_gmtime(last_tick, &tm);
206
- size_t len = http_date2rfc2109(RSTRING_PTR(str), &tm);
207
- rb_str_set_len(str, len);
208
- return str;
209
- (void)self;
210
- }
211
-
212
- /* *****************************************************************************
213
- Ruby Initialization
214
- ***************************************************************************** */
215
-
216
- void iodine_init_helpers(void) {
217
- iodine_to_i_func_id = rb_intern("to_i");
218
- IodineUTF8Encoding = rb_enc_find("UTF-8");
219
- VALUE tmp = rb_define_module_under(IodineModule, "Rack");
220
- // clang-format off
221
- /*
222
- Iodine does NOT monkey patch Rack automatically. However, it's possible and recommended to moneky patch Rack::Utils to use the methods in this module.
223
-
224
- Choosing to monkey patch Rack::Utils could offer significant performance gains for some applications. i.e. (on my machine):
225
-
226
- require 'iodine'
227
- require 'rack'
228
- # a String in need of decoding
229
- s = '%E3%83%AB%E3%83%93%E3%82%A4%E3%82%B9%E3%81%A8'
230
- Benchmark.bm do |bm|
231
- # Pre-Patch
232
- bm.report(" Rack.unescape") {1_000_000.times { Rack::Utils.unescape s } }
233
- bm.report(" Rack.rfc2822") {1_000_000.times { Rack::Utils.rfc2822(Time.now) } }
234
- bm.report(" Rack.rfc2109") {1_000_000.times { Rack::Utils.rfc2109(Time.now) } }
235
- # Perform Patch
236
- Iodine.patch_rack
237
- puts " --- Monkey Patching Rack ---"
238
- # Post Patch
239
- bm.report("Patched.unescape") {1_000_000.times { Rack::Utils.unescape s } }
240
- bm.report(" Patched.rfc2822") {1_000_000.times { Rack::Utils.rfc2822(Time.now) } }
241
- bm.report(" Patched.rfc2109") {1_000_000.times { Rack::Utils.rfc2109(Time.now) } }
242
- end && nil
243
-
244
- Results:
245
- user system total real
246
- Rack.unescape 8.706881 0.019995 8.726876 ( 8.740530)
247
- Rack.rfc2822 3.270305 0.007519 3.277824 ( 3.279416)
248
- Rack.rfc2109 3.152188 0.003852 3.156040 ( 3.157975)
249
- --- Monkey Patching Rack ---
250
- Patched.unescape 0.327231 0.003125 0.330356 ( 0.337090)
251
- Patched.rfc2822 0.691304 0.003330 0.694634 ( 0.701172)
252
- Patched.rfc2109 0.685029 0.001956 0.686985 ( 0.687607)
253
-
254
- */
255
- tmp = rb_define_module_under(tmp, "Utils");
256
- // clang-format on
257
- rb_define_module_function(tmp, "decode_url!", url_decode_inplace, 1);
258
- rb_define_module_function(tmp, "decode_url", url_decode, 1);
259
- rb_define_module_function(tmp, "decode_path!", path_decode_inplace, 1);
260
- rb_define_module_function(tmp, "decode_path", path_decode, 1);
261
- rb_define_module_function(tmp, "time2str", date_str, -1);
262
- rb_define_module_function(tmp, "rfc2109", iodine_rfc2109, 1);
263
- rb_define_module_function(tmp, "rfc2822", iodine_rfc2822, 1);
264
-
265
- /*
266
- The monkey-patched methods are in this module, allowing Iodine::Rack::Utils to
267
- include non-patched methods as well.
268
- */
269
- tmp = rb_define_module_under(IodineBaseModule, "MonkeyPatch");
270
- tmp = rb_define_module_under(tmp, "RackUtils");
271
- // clang-format on
272
- /* we define it all twice for easier monkey patching */
273
- rb_define_method(tmp, "unescape", unescape, -1);
274
- rb_define_method(tmp, "unescape_path", path_decode, 1);
275
- rb_define_method(tmp, "rfc2109", iodine_rfc2109, 1);
276
- rb_define_method(tmp, "rfc2822", iodine_rfc2822, 1);
277
- rb_define_singleton_method(tmp, "unescape", unescape, -1);
278
- rb_define_singleton_method(tmp, "unescape_path", path_decode, 1);
279
- rb_define_singleton_method(tmp, "rfc2109", iodine_rfc2109, 1);
280
- rb_define_singleton_method(tmp, "rfc2822", iodine_rfc2822, 1);
281
- // rb_define_module_function(IodineUtils, "time2str", date_str, -1);
282
- }
@@ -1,12 +0,0 @@
1
- #ifndef H_IODINE_HELPERS_H
2
- #define H_IODINE_HELPERS_H
3
- /*
4
- Copyright: Boaz segev, 2016-2018
5
- License: MIT
6
-
7
- Feel free to copy, use and enjoy according to the license provided.
8
- */
9
-
10
- void iodine_init_helpers(void);
11
-
12
- #endif