flamboyant 0.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 920879ab8f46af5654ca490148519289555c8d38481efddd76b5a0ac5e92b3d9
4
+ data.tar.gz: 9d94c9bf018c97b8674d55436c24974a80901a0954b75f39e4a903a78415300b
5
+ SHA512:
6
+ metadata.gz: 6a024534dd44d2aa49d8794ea68b5871a3ea59ec4ce1b44700bc7698dbc179d5f2f237529e50132b4f08072a3d6d1a080078028a9f4a79840005f157d932e255
7
+ data.tar.gz: 751939d9707d984ae233c744d186394ee2daf0444ec99c995a4185f518306ab9cd5d875248a195a100b8162fc3a9ce743c05efaebbf9e9c1162708ea43e976bc
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.1
data/Cargo.lock ADDED
@@ -0,0 +1,420 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "0.7.18"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "ansi_term"
16
+ version = "0.12.1"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
19
+ dependencies = [
20
+ "winapi",
21
+ ]
22
+
23
+ [[package]]
24
+ name = "atty"
25
+ version = "0.2.14"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
28
+ dependencies = [
29
+ "hermit-abi",
30
+ "libc",
31
+ "winapi",
32
+ ]
33
+
34
+ [[package]]
35
+ name = "bindgen"
36
+ version = "0.59.2"
37
+ source = "registry+https://github.com/rust-lang/crates.io-index"
38
+ checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8"
39
+ dependencies = [
40
+ "bitflags",
41
+ "cexpr",
42
+ "clang-sys",
43
+ "clap",
44
+ "env_logger",
45
+ "lazy_static",
46
+ "lazycell",
47
+ "log",
48
+ "peeking_take_while",
49
+ "proc-macro2",
50
+ "quote",
51
+ "regex",
52
+ "rustc-hash",
53
+ "shlex",
54
+ "which",
55
+ ]
56
+
57
+ [[package]]
58
+ name = "bitflags"
59
+ version = "1.3.2"
60
+ source = "registry+https://github.com/rust-lang/crates.io-index"
61
+ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
62
+
63
+ [[package]]
64
+ name = "cc"
65
+ version = "1.0.73"
66
+ source = "registry+https://github.com/rust-lang/crates.io-index"
67
+ checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
68
+
69
+ [[package]]
70
+ name = "cexpr"
71
+ version = "0.6.0"
72
+ source = "registry+https://github.com/rust-lang/crates.io-index"
73
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
74
+ dependencies = [
75
+ "nom",
76
+ ]
77
+
78
+ [[package]]
79
+ name = "cfg-if"
80
+ version = "1.0.0"
81
+ source = "registry+https://github.com/rust-lang/crates.io-index"
82
+ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
83
+
84
+ [[package]]
85
+ name = "clang-sys"
86
+ version = "1.3.3"
87
+ source = "registry+https://github.com/rust-lang/crates.io-index"
88
+ checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b"
89
+ dependencies = [
90
+ "glob",
91
+ "libc",
92
+ "libloading",
93
+ ]
94
+
95
+ [[package]]
96
+ name = "clap"
97
+ version = "2.34.0"
98
+ source = "registry+https://github.com/rust-lang/crates.io-index"
99
+ checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
100
+ dependencies = [
101
+ "ansi_term",
102
+ "atty",
103
+ "bitflags",
104
+ "strsim",
105
+ "textwrap",
106
+ "unicode-width",
107
+ "vec_map",
108
+ ]
109
+
110
+ [[package]]
111
+ name = "coffret"
112
+ version = "0.0.3"
113
+ source = "registry+https://github.com/rust-lang/crates.io-index"
114
+ checksum = "efb0b42fe7c89fec1939af9293f94403f32bab4ac86769dbd8362d34c40e649c"
115
+ dependencies = [
116
+ "libc",
117
+ "rb-sys",
118
+ ]
119
+
120
+ [[package]]
121
+ name = "ctrlc"
122
+ version = "3.2.2"
123
+ source = "registry+https://github.com/rust-lang/crates.io-index"
124
+ checksum = "b37feaa84e6861e00a1f5e5aa8da3ee56d605c9992d33e082786754828e20865"
125
+ dependencies = [
126
+ "nix",
127
+ "winapi",
128
+ ]
129
+
130
+ [[package]]
131
+ name = "either"
132
+ version = "1.6.1"
133
+ source = "registry+https://github.com/rust-lang/crates.io-index"
134
+ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
135
+
136
+ [[package]]
137
+ name = "env_logger"
138
+ version = "0.9.0"
139
+ source = "registry+https://github.com/rust-lang/crates.io-index"
140
+ checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
141
+ dependencies = [
142
+ "atty",
143
+ "humantime",
144
+ "log",
145
+ "regex",
146
+ "termcolor",
147
+ ]
148
+
149
+ [[package]]
150
+ name = "flamboyant"
151
+ version = "0.1.0"
152
+ dependencies = [
153
+ "coffret",
154
+ "ctrlc",
155
+ "libc",
156
+ "rb-sys",
157
+ ]
158
+
159
+ [[package]]
160
+ name = "glob"
161
+ version = "0.3.0"
162
+ source = "registry+https://github.com/rust-lang/crates.io-index"
163
+ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
164
+
165
+ [[package]]
166
+ name = "hermit-abi"
167
+ version = "0.1.19"
168
+ source = "registry+https://github.com/rust-lang/crates.io-index"
169
+ checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
170
+ dependencies = [
171
+ "libc",
172
+ ]
173
+
174
+ [[package]]
175
+ name = "humantime"
176
+ version = "2.1.0"
177
+ source = "registry+https://github.com/rust-lang/crates.io-index"
178
+ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
179
+
180
+ [[package]]
181
+ name = "lazy_static"
182
+ version = "1.4.0"
183
+ source = "registry+https://github.com/rust-lang/crates.io-index"
184
+ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
185
+
186
+ [[package]]
187
+ name = "lazycell"
188
+ version = "1.3.0"
189
+ source = "registry+https://github.com/rust-lang/crates.io-index"
190
+ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
191
+
192
+ [[package]]
193
+ name = "libc"
194
+ version = "0.2.126"
195
+ source = "registry+https://github.com/rust-lang/crates.io-index"
196
+ checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
197
+
198
+ [[package]]
199
+ name = "libloading"
200
+ version = "0.7.3"
201
+ source = "registry+https://github.com/rust-lang/crates.io-index"
202
+ checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
203
+ dependencies = [
204
+ "cfg-if",
205
+ "winapi",
206
+ ]
207
+
208
+ [[package]]
209
+ name = "linkify"
210
+ version = "0.8.1"
211
+ source = "registry+https://github.com/rust-lang/crates.io-index"
212
+ checksum = "28d9967eb7d0bc31c39c6f52e8fce42991c0cd1f7a2078326f0b7a399a584c8d"
213
+ dependencies = [
214
+ "memchr",
215
+ ]
216
+
217
+ [[package]]
218
+ name = "log"
219
+ version = "0.4.17"
220
+ source = "registry+https://github.com/rust-lang/crates.io-index"
221
+ checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
222
+ dependencies = [
223
+ "cfg-if",
224
+ ]
225
+
226
+ [[package]]
227
+ name = "memchr"
228
+ version = "2.5.0"
229
+ source = "registry+https://github.com/rust-lang/crates.io-index"
230
+ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
231
+
232
+ [[package]]
233
+ name = "minimal-lexical"
234
+ version = "0.2.1"
235
+ source = "registry+https://github.com/rust-lang/crates.io-index"
236
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
237
+
238
+ [[package]]
239
+ name = "nix"
240
+ version = "0.24.1"
241
+ source = "registry+https://github.com/rust-lang/crates.io-index"
242
+ checksum = "8f17df307904acd05aa8e32e97bb20f2a0df1728bbc2d771ae8f9a90463441e9"
243
+ dependencies = [
244
+ "bitflags",
245
+ "cfg-if",
246
+ "libc",
247
+ ]
248
+
249
+ [[package]]
250
+ name = "nom"
251
+ version = "7.1.1"
252
+ source = "registry+https://github.com/rust-lang/crates.io-index"
253
+ checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
254
+ dependencies = [
255
+ "memchr",
256
+ "minimal-lexical",
257
+ ]
258
+
259
+ [[package]]
260
+ name = "peeking_take_while"
261
+ version = "0.1.2"
262
+ source = "registry+https://github.com/rust-lang/crates.io-index"
263
+ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
264
+
265
+ [[package]]
266
+ name = "pkg-config"
267
+ version = "0.3.25"
268
+ source = "registry+https://github.com/rust-lang/crates.io-index"
269
+ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
270
+
271
+ [[package]]
272
+ name = "proc-macro2"
273
+ version = "1.0.39"
274
+ source = "registry+https://github.com/rust-lang/crates.io-index"
275
+ checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f"
276
+ dependencies = [
277
+ "unicode-ident",
278
+ ]
279
+
280
+ [[package]]
281
+ name = "quote"
282
+ version = "1.0.18"
283
+ source = "registry+https://github.com/rust-lang/crates.io-index"
284
+ checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
285
+ dependencies = [
286
+ "proc-macro2",
287
+ ]
288
+
289
+ [[package]]
290
+ name = "rb-sys"
291
+ version = "0.9.3"
292
+ source = "registry+https://github.com/rust-lang/crates.io-index"
293
+ checksum = "e5397d604589a1403fbd49b1af9265b88cdf12975cc1b2dafc7574af7ff6c5bf"
294
+ dependencies = [
295
+ "bindgen",
296
+ "cc",
297
+ "lazy_static",
298
+ "linkify",
299
+ "pkg-config",
300
+ "shell-words",
301
+ ]
302
+
303
+ [[package]]
304
+ name = "regex"
305
+ version = "1.5.6"
306
+ source = "registry+https://github.com/rust-lang/crates.io-index"
307
+ checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1"
308
+ dependencies = [
309
+ "aho-corasick",
310
+ "memchr",
311
+ "regex-syntax",
312
+ ]
313
+
314
+ [[package]]
315
+ name = "regex-syntax"
316
+ version = "0.6.26"
317
+ source = "registry+https://github.com/rust-lang/crates.io-index"
318
+ checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
319
+
320
+ [[package]]
321
+ name = "rustc-hash"
322
+ version = "1.1.0"
323
+ source = "registry+https://github.com/rust-lang/crates.io-index"
324
+ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
325
+
326
+ [[package]]
327
+ name = "shell-words"
328
+ version = "1.1.0"
329
+ source = "registry+https://github.com/rust-lang/crates.io-index"
330
+ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
331
+
332
+ [[package]]
333
+ name = "shlex"
334
+ version = "1.1.0"
335
+ source = "registry+https://github.com/rust-lang/crates.io-index"
336
+ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
337
+
338
+ [[package]]
339
+ name = "strsim"
340
+ version = "0.8.0"
341
+ source = "registry+https://github.com/rust-lang/crates.io-index"
342
+ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
343
+
344
+ [[package]]
345
+ name = "termcolor"
346
+ version = "1.1.3"
347
+ source = "registry+https://github.com/rust-lang/crates.io-index"
348
+ checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
349
+ dependencies = [
350
+ "winapi-util",
351
+ ]
352
+
353
+ [[package]]
354
+ name = "textwrap"
355
+ version = "0.11.0"
356
+ source = "registry+https://github.com/rust-lang/crates.io-index"
357
+ checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
358
+ dependencies = [
359
+ "unicode-width",
360
+ ]
361
+
362
+ [[package]]
363
+ name = "unicode-ident"
364
+ version = "1.0.0"
365
+ source = "registry+https://github.com/rust-lang/crates.io-index"
366
+ checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee"
367
+
368
+ [[package]]
369
+ name = "unicode-width"
370
+ version = "0.1.9"
371
+ source = "registry+https://github.com/rust-lang/crates.io-index"
372
+ checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
373
+
374
+ [[package]]
375
+ name = "vec_map"
376
+ version = "0.8.2"
377
+ source = "registry+https://github.com/rust-lang/crates.io-index"
378
+ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
379
+
380
+ [[package]]
381
+ name = "which"
382
+ version = "4.2.5"
383
+ source = "registry+https://github.com/rust-lang/crates.io-index"
384
+ checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae"
385
+ dependencies = [
386
+ "either",
387
+ "lazy_static",
388
+ "libc",
389
+ ]
390
+
391
+ [[package]]
392
+ name = "winapi"
393
+ version = "0.3.9"
394
+ source = "registry+https://github.com/rust-lang/crates.io-index"
395
+ checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
396
+ dependencies = [
397
+ "winapi-i686-pc-windows-gnu",
398
+ "winapi-x86_64-pc-windows-gnu",
399
+ ]
400
+
401
+ [[package]]
402
+ name = "winapi-i686-pc-windows-gnu"
403
+ version = "0.4.0"
404
+ source = "registry+https://github.com/rust-lang/crates.io-index"
405
+ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
406
+
407
+ [[package]]
408
+ name = "winapi-util"
409
+ version = "0.1.5"
410
+ source = "registry+https://github.com/rust-lang/crates.io-index"
411
+ checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
412
+ dependencies = [
413
+ "winapi",
414
+ ]
415
+
416
+ [[package]]
417
+ name = "winapi-x86_64-pc-windows-gnu"
418
+ version = "0.4.0"
419
+ source = "registry+https://github.com/rust-lang/crates.io-index"
420
+ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
data/Cargo.toml ADDED
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "flamboyant"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+ [lib]
8
+ crate-type = ["cdylib"]
9
+
10
+ [dependencies]
11
+ libc = "^0.2"
12
+ rb-sys = { version = "^0.9", features = ["link-ruby"] }
13
+ coffret = "0.0.3"
14
+ ctrlc = "3.2.2"
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in flamboyant.gemspec
6
+ gemspec
7
+
8
+ gem "rake"
data/Gemfile.lock ADDED
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ flamboyant (0.1.0.rc1)
5
+ rack
6
+ webrick
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ rack (2.2.3)
12
+ rake (13.0.6)
13
+ webrick (1.7.0)
14
+
15
+ PLATFORMS
16
+ arm64-darwin-21
17
+
18
+ DEPENDENCIES
19
+ flamboyant!
20
+ rake
21
+
22
+ BUNDLED WITH
23
+ 2.4.0.dev
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright 2022 - Uchio Kondo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Flamboyant
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flamboyant`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'flamboyant'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install flamboyant
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/udzura/flamboyant.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/config.ru ADDED
@@ -0,0 +1,5 @@
1
+ app = lambda {|_env|
2
+ return [200, {"Content-Type" => "text/plain"}, ["Hello rack app"]]
3
+ }
4
+
5
+ run app
data/examples/serve.rs ADDED
@@ -0,0 +1,7 @@
1
+ extern crate flamboyant;
2
+
3
+ fn main() {
4
+ unsafe {
5
+ flamboyant::core::rb_flamboyant_serve(flamboyant::ruby_ext::Nil.into());
6
+ }
7
+ }
@@ -0,0 +1,32 @@
1
+ require 'fileutils'
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "flamboyant/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flamboyant"
8
+ spec.version = Flamboyant::VERSION
9
+ spec.authors = ["Uchio Kondo"]
10
+ spec.email = ["udzura@udzura.jp"]
11
+
12
+ spec.summary = %q{Experimental web server for Ruby, written as a Rust-made gem}
13
+ spec.description = %q{Experimental web server for Ruby, written as a Rust-made gem}
14
+ spec.homepage = "https://github.com/udzura/flamboyant"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(__dir__) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ (f == __FILE__) || \
22
+ f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
23
+ end + ["Cargo.lock"]
24
+ end
25
+ # spec.bindir = "exe"
26
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ spec.extensions = ["Cargo.toml"]
29
+
30
+ spec.add_dependency "rack"
31
+ spec.add_dependency "webrick"
32
+ end
@@ -0,0 +1,3 @@
1
+ class Flamboyant
2
+ VERSION = "0.1.0.rc1"
3
+ end
data/lib/flamboyant.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "flamboyant/version"
2
+
3
+ class Flamboyant
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
7
+
8
+ require 'flamboyant.so'
@@ -0,0 +1,151 @@
1
+ require 'flamboyant'
2
+ require 'webrick'
3
+ require 'webrick/httprequest'
4
+ require 'rack'
5
+ require 'uri'
6
+ require 'stringio'
7
+
8
+ class WEBrick::HTTPRequest
9
+ def generate_from_string(reqline, lines)
10
+ @peeraddr = [] # TODO set in Rust
11
+ @addr = []
12
+
13
+ read_request_one_line(reqline)
14
+ if @http_version.major > 0
15
+ read_header_str(lines)
16
+ @header['cookie'].each{|cookie|
17
+ @cookies += WEBrick::Cookie::parse(cookie)
18
+ }
19
+ @accept = WEBrick::HTTPUtils.parse_qvalues(self['accept'])
20
+ @accept_charset = WEBrick::HTTPUtils.parse_qvalues(self['accept-charset'])
21
+ @accept_encoding = WEBrick::HTTPUtils.parse_qvalues(self['accept-encoding'])
22
+ @accept_language = WEBrick::HTTPUtils.parse_qvalues(self['accept-language'])
23
+ end
24
+ return if @request_method == "CONNECT"
25
+ return if @unparsed_uri == "*"
26
+
27
+ begin
28
+ setup_forwarded_info
29
+ @request_uri = parse_uri(@unparsed_uri)
30
+ @path = WEBrick::HTTPUtils::unescape(@request_uri.path)
31
+ @path = WEBrick::HTTPUtils::normalize_path(@path)
32
+ @host = @request_uri.host
33
+ @port = @request_uri.port
34
+ @query_string = @request_uri.query
35
+ @script_name = ""
36
+ @path_info = @path.dup
37
+ rescue
38
+ raise WEBrick::HTTPStatus::BadRequest, "bad URI `#{@unparsed_uri}'."
39
+ end
40
+
41
+ if /\Aclose\z/io =~ self["connection"]
42
+ @keep_alive = false
43
+ elsif /\Akeep-alive\z/io =~ self["connection"]
44
+ @keep_alive = true
45
+ elsif @http_version < "1.1"
46
+ @keep_alive = false
47
+ else
48
+ @keep_alive = true
49
+ end
50
+ end
51
+
52
+ def read_request_one_line(line)
53
+ @request_line = line
54
+ @request_bytes = @request_line.bytesize
55
+ if @request_bytes >= WEBrick::HTTPRequest::MAX_URI_LENGTH and @request_line[-1, 1] != LF
56
+ raise WEBrick::HTTPStatus::RequestURITooLarge
57
+ end
58
+
59
+ @request_time = Time.now
60
+ if /^(\S+)\s+(\S++)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ @request_line
61
+ @request_method = $1
62
+ @unparsed_uri = $2
63
+ @http_version = WEBrick::HTTPVersion.new($3 ? $3 : "0.9")
64
+ else
65
+ rl = @request_line.sub(/\x0d?\x0a\z/o, '')
66
+ raise WEBrick::HTTPStatus::BadRequest, "bad Request-Line `#{rl}'."
67
+ end
68
+ end
69
+
70
+ def read_header_str(lines)
71
+ lines.each do |line|
72
+ break if /\A(\r\n|\n)\z/om =~ line
73
+ if (@request_bytes += line.bytesize) > WEBrick::HTTPRequest::MAX_URI_LENGTH
74
+ raise WEBrick::HTTPStatus::RequestEntityTooLarge, 'headers too large'
75
+ end
76
+ @raw_header << line
77
+ end
78
+ @header = WEBrick::HTTPUtils::parse_header(@raw_header.join)
79
+ end
80
+ end
81
+
82
+ module Rack
83
+ module Handler
84
+ class Flamboyant
85
+ SERVER_NAME = "Flamboyant/0.1.0 experimental"
86
+
87
+ def self.run(app, **options)
88
+ ENV["PORT"] ||= options[:Port]&.to_s || "9292"
89
+
90
+ server = ::Flamboyant.new
91
+ config = ::WEBrick::Config::HTTP.merge(
92
+ ServerSoftware: SERVER_NAME
93
+ )
94
+ server.serve(
95
+ lambda { |req|
96
+ p req
97
+
98
+ begin
99
+ head, rbody = req.split("\r\n\r\n")
100
+ heads = head.lines
101
+ wreq = ::WEBrick::HTTPRequest.new(config)
102
+ wreq.generate_from_string(heads[0], heads[1..heads.size])
103
+
104
+ env = wreq.meta_vars
105
+ env.delete_if { |k, v| v.nil? }
106
+ rack_input = StringIO.new(rbody || "")
107
+ rack_input.set_encoding(Encoding::BINARY)
108
+
109
+ env.update(
110
+ ::Rack::RACK_VERSION => ::Rack::VERSION,
111
+ ::Rack::RACK_INPUT => rack_input,
112
+ ::Rack::RACK_ERRORS => $stderr,
113
+ ::Rack::RACK_URL_SCHEME => ["yes", "on", "1"].include?(env[::Rack::HTTPS]) ? "https" : "http",
114
+ ::Rack::RACK_IS_HIJACK => true,
115
+ ::Rack::RACK_HIJACK => lambda { raise NotImplementedError, "only partial hijack is supported."},
116
+ ::Rack::RACK_HIJACK_IO => nil,
117
+ 'rack.multithread' => false,
118
+ 'rack.multiprocess' => false,
119
+ 'rack.run_once' => false
120
+ )
121
+
122
+ status, headers, body = app.call(env)
123
+ headers["Server"] = SERVER_NAME
124
+ res = [
125
+ "HTTP/1.1 #{status} OK",
126
+ *headers.map{|k, v| "#{k}: #{v}"},
127
+ "",
128
+ body.join
129
+ ].join("\r\n")
130
+
131
+ return res
132
+ rescue => e
133
+ body = e.inspect + e.backtrace.join("\n")
134
+
135
+ res = [
136
+ "HTTP/1.1 503 Internal Server Error",
137
+ "Content-Type: text/plain",
138
+ "Content-Length: #{body.size}",
139
+ "",
140
+ body
141
+ ].join("\r\n")
142
+ return res
143
+ end
144
+ }
145
+ )
146
+ end
147
+ end
148
+
149
+ register 'flamboyant', Flamboyant
150
+ end
151
+ end
data/src/core.rs ADDED
@@ -0,0 +1,70 @@
1
+ use std::ffi::CString;
2
+ use std::io::prelude::*;
3
+ use std::net::TcpListener;
4
+ use std::net::TcpStream;
5
+ use std::slice;
6
+
7
+ use rb_sys::*;
8
+
9
+ const _HELLO: &'static str = "<!DOCTYPE html>
10
+ <html lang=\"en\">
11
+ <head>
12
+ <meta charset=\"utf-8\">
13
+ <title>Hello!</title>
14
+ </head>
15
+ <body>
16
+ <h1>Hello!</h1>
17
+ <p>Hi from Rust</p>
18
+ </body>
19
+ </html>";
20
+
21
+ #[no_mangle]
22
+ pub unsafe extern "C" fn rb_flamboyant_serve(_slf: RubyValue, callback: RubyValue) -> RubyValue {
23
+ serve(callback);
24
+ return crate::ruby_ext::Nil.into();
25
+ }
26
+
27
+ fn serve(app: RubyValue) {
28
+ unsafe {
29
+ libc::signal(libc::SIGINT, libc::SIG_DFL);
30
+ libc::signal(libc::SIGTERM, libc::SIG_DFL);
31
+ }
32
+
33
+ let listner = TcpListener::bind("127.0.0.1:17878").unwrap();
34
+ println!(
35
+ "Listening: http://{}",
36
+ listner.local_addr().unwrap().to_string()
37
+ );
38
+
39
+ for stream in listner.incoming() {
40
+ let stream = stream.unwrap();
41
+ handle_connection(app, stream);
42
+ }
43
+ }
44
+
45
+ fn handle_connection(app: RubyValue, mut stream: TcpStream) {
46
+ let mut buffer = [0; 4096];
47
+
48
+ stream.read(&mut buffer).unwrap();
49
+ let index = buffer
50
+ .iter()
51
+ .enumerate()
52
+ .find(|(_i, chr)| return **chr == ('\0' as u8))
53
+ .unwrap();
54
+ let string = CString::new(&buffer[..index.0]).unwrap();
55
+
56
+ let reqstring = unsafe { rb_utf8_str_new_cstr(string.as_ptr()) };
57
+ let call = CString::new("call").unwrap();
58
+ let args = vec![reqstring];
59
+ let response = unsafe { rb_funcallv(app, rb_intern(call.as_ptr()), 1, args.as_ptr()) };
60
+ let mut response = Box::new(response);
61
+
62
+ let bytes: *const i8 = unsafe { rb_string_value_ptr(response.as_mut()) };
63
+ let len = unsafe { macros::RSTRING_LEN(response.as_ref().clone()) };
64
+
65
+ let bytes_: &[i8] = unsafe { slice::from_raw_parts(bytes, len as usize) };
66
+ let bytes: Vec<u8> = bytes_.iter().map(|v| *v as u8).collect();
67
+
68
+ stream.write(&bytes).unwrap();
69
+ stream.flush().unwrap();
70
+ }
data/src/lib.rs ADDED
@@ -0,0 +1,40 @@
1
+ pub mod core;
2
+ pub mod ruby_ext;
3
+
4
+ use std::error::Error;
5
+
6
+ use coffret::*;
7
+
8
+ // #[cfg(test)]
9
+ // mod tests {
10
+
11
+ // #[test]
12
+ // fn it_works() {
13
+ // let result = 2 + 2;
14
+ // assert_eq!(result, 4);
15
+ // }
16
+ // }
17
+
18
+ fn init_flamboyant_internal() -> Result<(), Box<dyn Error>> {
19
+ println!("Rust loaded");
20
+ let object = class::object_class();
21
+ let klass = class::define_class("Flamboyant", object);
22
+
23
+ //unsafe { rb_define_singleton_method(klass, function_name.as_ptr(), Some(test_hola), 0) }
24
+
25
+ //let callback = class::make_callback(&crate::core::rb_flamboyant_serve);
26
+ let callback: crate::ruby_ext::RubyFn =
27
+ (crate::core::rb_flamboyant_serve as unsafe extern "C" fn(u64, u64) -> u64).into();
28
+
29
+ class::define_method(klass, "serve", callback.into(), 1);
30
+ Ok(())
31
+ }
32
+
33
+ #[allow(non_snake_case)]
34
+ #[no_mangle]
35
+ pub extern "C" fn Init_flamboyant() {
36
+ match init_flamboyant_internal() {
37
+ Err(e) => exception::rustly_raise(e.as_ref()),
38
+ Ok(_) => {}
39
+ }
40
+ }
data/src/ruby_ext.rs ADDED
@@ -0,0 +1,72 @@
1
+ use rb_sys::*;
2
+
3
+ #[repr(C)]
4
+ pub struct WrappedRubyValue {
5
+ value: u32,
6
+ padding: u32,
7
+ }
8
+
9
+ impl From<WrappedRubyValue> for RubyValue {
10
+ fn from(from: WrappedRubyValue) -> Self {
11
+ let v = unsafe { std::mem::transmute::<WrappedRubyValue, RubyValue>(from) };
12
+ v
13
+ }
14
+ }
15
+
16
+ #[allow(non_upper_case_globals)]
17
+ pub const True: WrappedRubyValue = WrappedRubyValue {
18
+ value: ruby_special_consts::RUBY_Qtrue as u32,
19
+ padding: 0,
20
+ };
21
+
22
+ #[allow(non_upper_case_globals)]
23
+ pub const False: WrappedRubyValue = WrappedRubyValue {
24
+ value: ruby_special_consts::RUBY_Qfalse as u32,
25
+ padding: 0,
26
+ };
27
+
28
+ #[allow(non_upper_case_globals)]
29
+ pub const Nil: WrappedRubyValue = WrappedRubyValue {
30
+ value: ruby_special_consts::RUBY_Qnil as u32,
31
+ padding: 0,
32
+ };
33
+
34
+ pub struct RubyFn {
35
+ value: unsafe extern "C" fn() -> RubyValue,
36
+ }
37
+
38
+ impl From<RubyFn> for unsafe extern "C" fn() -> RubyValue {
39
+ fn from(from: RubyFn) -> Self {
40
+ from.value
41
+ }
42
+ }
43
+
44
+ impl From<unsafe extern "C" fn() -> RubyValue> for RubyFn {
45
+ fn from(from: unsafe extern "C" fn() -> RubyValue) -> Self {
46
+ RubyFn { value: from }
47
+ }
48
+ }
49
+
50
+ impl From<unsafe extern "C" fn(RubyValue) -> RubyValue> for RubyFn {
51
+ fn from(from: unsafe extern "C" fn(RubyValue) -> RubyValue) -> Self {
52
+ let value = unsafe {
53
+ std::mem::transmute::<
54
+ unsafe extern "C" fn(RubyValue) -> RubyValue,
55
+ unsafe extern "C" fn() -> RubyValue,
56
+ >(from)
57
+ };
58
+ RubyFn { value }
59
+ }
60
+ }
61
+
62
+ impl From<unsafe extern "C" fn(RubyValue, RubyValue) -> RubyValue> for RubyFn {
63
+ fn from(from: unsafe extern "C" fn(RubyValue, RubyValue) -> RubyValue) -> Self {
64
+ let value = unsafe {
65
+ std::mem::transmute::<
66
+ unsafe extern "C" fn(RubyValue, RubyValue) -> RubyValue,
67
+ unsafe extern "C" fn() -> RubyValue,
68
+ >(from)
69
+ };
70
+ RubyFn { value }
71
+ }
72
+ }
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flamboyant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Uchio Kondo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-06 00:00:00.000000000 Z
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: webrick
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'
41
+ description: Experimental web server for Ruby, written as a Rust-made gem
42
+ email:
43
+ - udzura@udzura.jp
44
+ executables: []
45
+ extensions:
46
+ - Cargo.toml
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".ruby-version"
50
+ - Cargo.lock
51
+ - Cargo.toml
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - config.ru
58
+ - examples/serve.rs
59
+ - flamboyant.gemspec
60
+ - lib/flamboyant.rb
61
+ - lib/flamboyant/version.rb
62
+ - lib/rack/handler/flamboyant.rb
63
+ - src/core.rs
64
+ - src/lib.rs
65
+ - src/ruby_ext.rs
66
+ homepage: https://github.com/udzura/flamboyant
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">"
82
+ - !ruby/object:Gem::Version
83
+ version: 1.3.1
84
+ requirements: []
85
+ rubygems_version: 3.4.0.dev
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Experimental web server for Ruby, written as a Rust-made gem
89
+ test_files: []