isomorfeus-iodine 0.7.47 → 0.7.48

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a017db20d4da0d99ec041f94af86227596b489d7a5323f1033786817a534c5c
4
- data.tar.gz: eeb6600aece29a3a17984edca815e475bac45f89c7103394ea6b9afe6e35c8f8
3
+ metadata.gz: 5b1237f665549395076af86532ffc564f4cef05add3014a5e9818cd674497602
4
+ data.tar.gz: e9e27c61cc6caa7ec67a56006681d7fe19850a88adcbcf4a14a4941dd8c3dd50
5
5
  SHA512:
6
- metadata.gz: 2c7ff4c05f48077939435d7924776396add7369ff081a878c5ffabb9e4dbcfdfa349ac8afb4cfce9e7451061bc7fbc70a9ee4111c3de68e98174876cb08e4595
7
- data.tar.gz: c42f137b14b1b1846a814be44343cbcd0b3f6ebbb1c7abf7eb39c4f0d372de36c39f14d914acd8ac43b6fd23eed4cffee9b5569c805d9d2ed2632d61cf670ae3
6
+ metadata.gz: 5296052972dc777a0bf1bb1d900d1fc2f94a2ce2c5667543fd1331cd915c883ac36ca4fc1dd584845a96ce80ec5e77604577851bc7289b4b4a01497c6235fade
7
+ data.tar.gz: 27a99318353419d531fd07538f63d6ce1fae88fc6cc55a23fb87950f861511cc257cea71edd7d8bdd06c184c7142f34a3d644b52931c6f1eb4cea2d7f7753a06
@@ -9,6 +9,7 @@ on:
9
9
  jobs:
10
10
  specs:
11
11
  strategy:
12
+ fail-fast: false
12
13
  matrix:
13
14
  os: [ubuntu-latest, macos-latest, windows-latest]
14
15
  runs-on: ${{ matrix.os }}
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,8 @@
1
+ image: ruby:3.1
2
+
3
+ before_script:
4
+ - bundle install -j $(nproc)
5
+
6
+ specs:
7
+ script:
8
+ - bundle exec rake
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
- gem 'pry'
5
4
  gem 'rspec'
6
5
  gem 'rack'
7
6
  gem 'http'
data/bin/console CHANGED
@@ -14,9 +14,5 @@ require "iodine"
14
14
  # You can add fixtures and/or initialization code here to make experimenting
15
15
  # with your gem easier. You can also use a different console, if you like.
16
16
 
17
- # (If you use this, don't forget to add pry to your Gemfile!)
18
- # require "pry"
19
- # Pry.start
20
-
21
17
  require "irb"
22
18
  IRB.start
@@ -0,0 +1,9 @@
1
+ image: ruby:3.1
2
+
3
+ pipelines:
4
+ default:
5
+ - step:
6
+ name: specs
7
+ script:
8
+ - bundle install
9
+ - bundle exec rake
@@ -1,282 +1,282 @@
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
+ /*
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
+ }
@@ -85,11 +85,7 @@ IO API
85
85
 
86
86
  static inline FIOBJ get_data(VALUE self) {
87
87
  VALUE i = rb_ivar_get(self, io_id);
88
- #ifdef __MINGW32__
89
88
  return (FIOBJ)NUM2ULL(i);
90
- #else
91
- return (FIOBJ)FIX2ULONG(i);
92
- #endif
93
89
  }
94
90
 
95
91
  static VALUE rio_rewind(VALUE self) {
@@ -1,3 +1,3 @@
1
1
  module Iodine
2
- VERSION = '0.7.47'.freeze
2
+ VERSION = '0.7.48'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-iodine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.47
4
+ version: 0.7.48
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-08 00:00:00.000000000 Z
11
+ date: 2022-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -122,6 +122,7 @@ files:
122
122
  - ".github/ISSUE_TEMPLATE/bug_report.md"
123
123
  - ".github/workflows/ruby.yml"
124
124
  - ".gitignore"
125
+ - ".gitlab-ci.yml"
125
126
  - ".rspec"
126
127
  - ".travis.yml"
127
128
  - ".yardopts"
@@ -141,6 +142,7 @@ files:
141
142
  - bin/poc/config.ru
142
143
  - bin/poc/gemfile
143
144
  - bin/poc/www/index.html
145
+ - bitbucket-pipelines.yml
144
146
  - examples/async_task.ru
145
147
  - examples/config.ru
146
148
  - examples/echo.ru
@@ -244,7 +246,7 @@ metadata:
244
246
  github_repo: ssh://github.com/isomorfeus/gems
245
247
  source_code_uri: https://github.com/isomorfeus/isomorfeus-iodine
246
248
  post_install_message: |-
247
- Thank you for installing Iodine 0.7.47.
249
+ Thank you for installing Iodine 0.7.48.
248
250
  Remember: if iodine supports your business, it's only fair to give value back (code contributions / donations) to Bo, see https://github.com/boazsegev/iodine
249
251
  rdoc_options: []
250
252
  require_paths:
@@ -267,7 +269,7 @@ requirements:
267
269
  - Ruby >= 2.5.0 recommended.
268
270
  - TLS requires OpenSSL >= 1.1.0.
269
271
  - Or Windows with Ruby >= 3.0.0 build with MingW and MingW as compiler.
270
- rubygems_version: 3.3.3
272
+ rubygems_version: 3.3.7
271
273
  signing_key:
272
274
  specification_version: 4
273
275
  summary: iodine build for Isomorfeus