itsi 0.1.11 → 0.1.12
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.
- checksums.yaml +4 -4
- data/Cargo.lock +1535 -45
- data/{sandbox/itsi_itsi_file/Itsi.rb → Itsi.rb} +19 -13
- data/Rakefile +8 -7
- data/crates/itsi_error/src/lib.rs +9 -0
- data/crates/itsi_rb_helpers/Cargo.toml +1 -0
- data/crates/itsi_rb_helpers/src/heap_value.rs +18 -0
- data/crates/itsi_rb_helpers/src/lib.rs +34 -7
- data/crates/itsi_server/Cargo.toml +69 -30
- data/crates/itsi_server/src/lib.rs +79 -147
- data/crates/itsi_server/src/{body_proxy → ruby_types/itsi_body_proxy}/big_bytes.rs +10 -5
- data/crates/itsi_server/src/{body_proxy/itsi_body_proxy.rs → ruby_types/itsi_body_proxy/mod.rs} +22 -3
- data/crates/itsi_server/src/ruby_types/itsi_grpc_request.rs +147 -0
- data/crates/itsi_server/src/ruby_types/itsi_grpc_response.rs +19 -0
- data/crates/itsi_server/src/ruby_types/itsi_grpc_stream/mod.rs +216 -0
- data/{gems/server/ext/itsi_server/src/request/itsi_request.rs → crates/itsi_server/src/ruby_types/itsi_http_request.rs} +101 -117
- data/crates/itsi_server/src/{response/itsi_response.rs → ruby_types/itsi_http_response.rs} +72 -41
- data/crates/itsi_server/src/ruby_types/itsi_server/file_watcher.rs +225 -0
- data/crates/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +355 -0
- data/crates/itsi_server/src/ruby_types/itsi_server.rs +82 -0
- data/crates/itsi_server/src/ruby_types/mod.rs +55 -0
- data/crates/itsi_server/src/server/bind.rs +13 -5
- data/crates/itsi_server/src/server/byte_frame.rs +32 -0
- data/crates/itsi_server/src/server/cache_store.rs +74 -0
- data/crates/itsi_server/src/server/itsi_service.rs +172 -0
- data/crates/itsi_server/src/server/lifecycle_event.rs +3 -0
- data/crates/itsi_server/src/server/listener.rs +102 -2
- data/crates/itsi_server/src/server/middleware_stack/middleware.rs +153 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/allow_list.rs +47 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_api_key.rs +58 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_basic.rs +82 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_jwt.rs +321 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/cache_control.rs +139 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/compression.rs +300 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/cors.rs +287 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/deny_list.rs +48 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/error_response.rs +127 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/etag.rs +191 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/grpc_service.rs +72 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/header_interpretation.rs +85 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/intrusion_protection.rs +195 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/log_requests.rs +82 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/mod.rs +82 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/proxy.rs +216 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/rate_limit.rs +124 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/redirect.rs +76 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/request_headers.rs +43 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/response_headers.rs +34 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +93 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/static_assets.rs +162 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/string_rewrite.rs +158 -0
- data/crates/itsi_server/src/server/middleware_stack/middlewares/token_source.rs +12 -0
- data/crates/itsi_server/src/server/middleware_stack/mod.rs +315 -0
- data/crates/itsi_server/src/server/mod.rs +8 -1
- data/crates/itsi_server/src/server/process_worker.rs +38 -12
- data/crates/itsi_server/src/server/rate_limiter.rs +565 -0
- data/crates/itsi_server/src/server/request_job.rs +11 -0
- data/crates/itsi_server/src/server/serve_strategy/cluster_mode.rs +119 -42
- data/crates/itsi_server/src/server/serve_strategy/mod.rs +9 -6
- data/crates/itsi_server/src/server/serve_strategy/single_mode.rs +256 -111
- data/crates/itsi_server/src/server/signal.rs +19 -0
- data/crates/itsi_server/src/server/static_file_server.rs +984 -0
- data/crates/itsi_server/src/server/thread_worker.rs +139 -94
- data/crates/itsi_server/src/server/types.rs +43 -0
- data/crates/itsi_server/test.md +14 -0
- data/crates/itsi_tracing/Cargo.toml +1 -0
- data/crates/itsi_tracing/src/lib.rs +216 -45
- data/docs/.gitignore +7 -0
- data/docs/.gitpod.yml +15 -0
- data/docs/Itsi.rb +17 -0
- data/docs/content/_index.md +17 -0
- data/docs/content/about.md +6 -0
- data/docs/content/docs/_index.md +18 -0
- data/docs/content/docs/first-page.md +9 -0
- data/docs/content/docs/folder/_index.md +10 -0
- data/docs/content/docs/folder/leaf.md +7 -0
- data/docs/go.mod +5 -0
- data/docs/go.sum +2 -0
- data/docs/hugo.yaml +77 -0
- data/examples/static_assets_example.rb +83 -0
- data/gems/_index.md +18 -0
- data/gems/scheduler/CODE_OF_CONDUCT.md +7 -0
- data/gems/scheduler/Cargo.lock +75 -14
- data/gems/scheduler/README.md +5 -0
- data/gems/scheduler/_index.md +7 -0
- data/gems/scheduler/itsi-scheduler.gemspec +4 -1
- data/gems/scheduler/lib/itsi/scheduler/version.rb +1 -1
- data/gems/scheduler/lib/itsi/scheduler.rb +2 -2
- data/gems/scheduler/test/test_file_io.rb +0 -1
- data/gems/scheduler/test/test_itsi_scheduler.rb +1 -1
- data/gems/server/CHANGELOG.md +5 -0
- data/gems/server/CODE_OF_CONDUCT.md +7 -0
- data/gems/server/Cargo.lock +1536 -45
- data/gems/server/README.md +4 -0
- data/gems/server/_index.md +6 -0
- data/gems/server/exe/itsi +33 -74
- data/gems/server/itsi-server.gemspec +3 -2
- data/gems/server/lib/itsi/{request.rb → http_request.rb} +29 -5
- data/gems/server/lib/itsi/http_response.rb +39 -0
- data/gems/server/lib/itsi/server/Itsi.rb +11 -19
- data/gems/server/lib/itsi/server/config/dsl.rb +506 -0
- data/gems/server/lib/itsi/server/config.rb +103 -8
- data/gems/server/lib/itsi/server/default_app/default_app.rb +38 -0
- data/gems/server/lib/itsi/server/grpc_interface.rb +213 -0
- data/gems/server/lib/itsi/server/rack/handler/itsi.rb +8 -17
- data/gems/server/lib/itsi/server/rack_interface.rb +23 -4
- data/gems/server/lib/itsi/server/scheduler_interface.rb +1 -1
- data/gems/server/lib/itsi/server/scheduler_mode.rb +4 -0
- data/gems/server/lib/itsi/server/signal_trap.rb +7 -1
- data/gems/server/lib/itsi/server/version.rb +1 -1
- data/gems/server/lib/itsi/server.rb +74 -63
- data/gems/server/lib/itsi/standard_headers.rb +86 -0
- data/gems/server/test/helpers/test_helper.rb +12 -12
- data/gems/server/test/test_itsi_server.rb +2 -2
- data/lib/itsi/version.rb +1 -1
- data/sandbox/itsi_file/Gemfile +11 -0
- data/sandbox/itsi_file/Gemfile.lock +69 -0
- data/sandbox/itsi_file/Itsi.rb +276 -0
- data/sandbox/itsi_file/error.html +2 -0
- data/sandbox/itsi_file/organisations_controller.rb +20 -0
- data/sandbox/itsi_file/public/assets/image.png +0 -0
- data/sandbox/itsi_file/public/assets/index.html +1 -0
- data/sandbox/itsi_sandbox_hanami/Gemfile.lock +2 -2
- data/sandbox/itsi_sandbox_rack/Gemfile.lock +2 -2
- data/sandbox/itsi_sandbox_rack/config.ru +2 -15
- data/sandbox/itsi_sandbox_rails/.dockerignore +2 -5
- data/sandbox/itsi_sandbox_rails/.github/workflows/ci.yml +1 -1
- data/sandbox/itsi_sandbox_rails/.gitignore +2 -1
- data/sandbox/itsi_sandbox_rails/Dockerfile +6 -9
- data/sandbox/itsi_sandbox_rails/Gemfile +16 -22
- data/sandbox/itsi_sandbox_rails/Gemfile.lock +100 -225
- data/sandbox/itsi_sandbox_rails/app/assets/config/manifest.js +4 -0
- data/sandbox/itsi_sandbox_rails/app/assets/stylesheets/application.css +11 -6
- data/sandbox/itsi_sandbox_rails/app/channels/application_cable/channel.rb +4 -0
- data/sandbox/itsi_sandbox_rails/app/channels/application_cable/connection.rb +4 -0
- data/sandbox/itsi_sandbox_rails/app/controllers/live_controller.rb +7 -8
- data/sandbox/itsi_sandbox_rails/app/controllers/uploads_controller.rb +0 -3
- data/sandbox/itsi_sandbox_rails/app/views/layouts/application.html.erb +2 -7
- data/sandbox/itsi_sandbox_rails/bin/docker-entrypoint +3 -4
- data/sandbox/itsi_sandbox_rails/bin/setup +8 -5
- data/sandbox/itsi_sandbox_rails/config/application.rb +1 -35
- data/sandbox/itsi_sandbox_rails/config/cable.yml +3 -10
- data/sandbox/itsi_sandbox_rails/config/credentials.yml.enc +1 -1
- data/sandbox/itsi_sandbox_rails/config/database.yml +9 -19
- data/sandbox/itsi_sandbox_rails/config/environment.rb +1 -1
- data/sandbox/itsi_sandbox_rails/config/environments/development.rb +21 -12
- data/sandbox/itsi_sandbox_rails/config/environments/production.rb +49 -34
- data/sandbox/itsi_sandbox_rails/config/environments/test.rb +19 -5
- data/sandbox/itsi_sandbox_rails/config/initializers/assets.rb +5 -0
- data/sandbox/itsi_sandbox_rails/config/initializers/filter_parameter_logging.rb +1 -1
- data/sandbox/itsi_sandbox_rails/config/initializers/permissions_policy.rb +13 -0
- data/sandbox/itsi_sandbox_rails/config/puma.rb +2 -9
- data/sandbox/itsi_sandbox_rails/config.ru +0 -1
- data/sandbox/itsi_sandbox_rails/db/migrate/20250301041554_create_posts.rb +1 -1
- data/sandbox/itsi_sandbox_rails/db/schema.rb +2 -2
- data/sandbox/itsi_sandbox_rails/lib/assets/.keep +0 -0
- data/sandbox/itsi_sandbox_rails/public/404.html +66 -113
- data/sandbox/itsi_sandbox_rails/public/406-unsupported-browser.html +65 -113
- data/sandbox/itsi_sandbox_rails/public/422.html +66 -113
- data/sandbox/itsi_sandbox_rails/public/500.html +65 -113
- data/sandbox/itsi_sandbox_rails/public/icon.png +0 -0
- data/sandbox/itsi_sandbox_rails/public/icon.svg +2 -2
- data/sandbox/itsi_sandbox_rails/test/channels/application_cable/connection_test.rb +13 -0
- data/sandbox/itsi_sandbox_roda/Gemfile.lock +3 -10
- data/tasks.txt +72 -35
- metadata +89 -139
- data/crates/itsi_server/src/body_proxy/mod.rs +0 -2
- data/crates/itsi_server/src/request/itsi_request.rs +0 -298
- data/crates/itsi_server/src/request/mod.rs +0 -1
- data/crates/itsi_server/src/response/mod.rs +0 -1
- data/crates/itsi_server/src/server/itsi_server.rs +0 -288
- data/gems/scheduler/ext/itsi_error/Cargo.lock +0 -368
- data/gems/scheduler/ext/itsi_error/Cargo.toml +0 -11
- data/gems/scheduler/ext/itsi_error/src/from.rs +0 -68
- data/gems/scheduler/ext/itsi_error/src/lib.rs +0 -24
- data/gems/scheduler/ext/itsi_instrument_entry/Cargo.toml +0 -15
- data/gems/scheduler/ext/itsi_instrument_entry/src/lib.rs +0 -31
- data/gems/scheduler/ext/itsi_rb_helpers/Cargo.lock +0 -355
- data/gems/scheduler/ext/itsi_rb_helpers/Cargo.toml +0 -10
- data/gems/scheduler/ext/itsi_rb_helpers/src/heap_value.rs +0 -121
- data/gems/scheduler/ext/itsi_rb_helpers/src/lib.rs +0 -201
- data/gems/scheduler/ext/itsi_scheduler/Cargo.toml +0 -24
- data/gems/scheduler/ext/itsi_scheduler/extconf.rb +0 -6
- data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler/io_helpers.rs +0 -56
- data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler/io_waiter.rs +0 -44
- data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler/timer.rs +0 -44
- data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler.rs +0 -308
- data/gems/scheduler/ext/itsi_scheduler/src/lib.rs +0 -38
- data/gems/scheduler/ext/itsi_server/Cargo.lock +0 -2956
- data/gems/scheduler/ext/itsi_server/Cargo.toml +0 -50
- data/gems/scheduler/ext/itsi_server/extconf.rb +0 -6
- data/gems/scheduler/ext/itsi_server/src/body_proxy/big_bytes.rs +0 -104
- data/gems/scheduler/ext/itsi_server/src/body_proxy/itsi_body_proxy.rs +0 -122
- data/gems/scheduler/ext/itsi_server/src/body_proxy/mod.rs +0 -2
- data/gems/scheduler/ext/itsi_server/src/env.rs +0 -43
- data/gems/scheduler/ext/itsi_server/src/lib.rs +0 -180
- data/gems/scheduler/ext/itsi_server/src/request/itsi_request.rs +0 -298
- data/gems/scheduler/ext/itsi_server/src/request/mod.rs +0 -1
- data/gems/scheduler/ext/itsi_server/src/response/itsi_response.rs +0 -357
- data/gems/scheduler/ext/itsi_server/src/response/mod.rs +0 -1
- data/gems/scheduler/ext/itsi_server/src/server/bind.rs +0 -174
- data/gems/scheduler/ext/itsi_server/src/server/bind_protocol.rs +0 -37
- data/gems/scheduler/ext/itsi_server/src/server/io_stream.rs +0 -104
- data/gems/scheduler/ext/itsi_server/src/server/itsi_server.rs +0 -288
- data/gems/scheduler/ext/itsi_server/src/server/lifecycle_event.rs +0 -9
- data/gems/scheduler/ext/itsi_server/src/server/listener.rs +0 -318
- data/gems/scheduler/ext/itsi_server/src/server/mod.rs +0 -11
- data/gems/scheduler/ext/itsi_server/src/server/process_worker.rs +0 -203
- data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +0 -260
- data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/mod.rs +0 -27
- data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/single_mode.rs +0 -276
- data/gems/scheduler/ext/itsi_server/src/server/signal.rs +0 -74
- data/gems/scheduler/ext/itsi_server/src/server/thread_worker.rs +0 -399
- data/gems/scheduler/ext/itsi_server/src/server/tls/locked_dir_cache.rs +0 -132
- data/gems/scheduler/ext/itsi_server/src/server/tls.rs +0 -265
- data/gems/scheduler/ext/itsi_tracing/Cargo.lock +0 -274
- data/gems/scheduler/ext/itsi_tracing/Cargo.toml +0 -16
- data/gems/scheduler/ext/itsi_tracing/src/lib.rs +0 -58
- data/gems/server/ext/itsi_error/Cargo.lock +0 -368
- data/gems/server/ext/itsi_error/Cargo.toml +0 -11
- data/gems/server/ext/itsi_error/src/from.rs +0 -68
- data/gems/server/ext/itsi_error/src/lib.rs +0 -24
- data/gems/server/ext/itsi_instrument_entry/Cargo.toml +0 -15
- data/gems/server/ext/itsi_instrument_entry/src/lib.rs +0 -31
- data/gems/server/ext/itsi_rb_helpers/Cargo.lock +0 -355
- data/gems/server/ext/itsi_rb_helpers/Cargo.toml +0 -10
- data/gems/server/ext/itsi_rb_helpers/src/heap_value.rs +0 -121
- data/gems/server/ext/itsi_rb_helpers/src/lib.rs +0 -201
- data/gems/server/ext/itsi_scheduler/Cargo.toml +0 -24
- data/gems/server/ext/itsi_scheduler/extconf.rb +0 -6
- data/gems/server/ext/itsi_scheduler/src/itsi_scheduler/io_helpers.rs +0 -56
- data/gems/server/ext/itsi_scheduler/src/itsi_scheduler/io_waiter.rs +0 -44
- data/gems/server/ext/itsi_scheduler/src/itsi_scheduler/timer.rs +0 -44
- data/gems/server/ext/itsi_scheduler/src/itsi_scheduler.rs +0 -308
- data/gems/server/ext/itsi_scheduler/src/lib.rs +0 -38
- data/gems/server/ext/itsi_server/Cargo.lock +0 -2956
- data/gems/server/ext/itsi_server/Cargo.toml +0 -50
- data/gems/server/ext/itsi_server/extconf.rb +0 -6
- data/gems/server/ext/itsi_server/src/body_proxy/big_bytes.rs +0 -104
- data/gems/server/ext/itsi_server/src/body_proxy/itsi_body_proxy.rs +0 -122
- data/gems/server/ext/itsi_server/src/body_proxy/mod.rs +0 -2
- data/gems/server/ext/itsi_server/src/env.rs +0 -43
- data/gems/server/ext/itsi_server/src/lib.rs +0 -180
- data/gems/server/ext/itsi_server/src/request/mod.rs +0 -1
- data/gems/server/ext/itsi_server/src/response/itsi_response.rs +0 -357
- data/gems/server/ext/itsi_server/src/response/mod.rs +0 -1
- data/gems/server/ext/itsi_server/src/server/bind.rs +0 -174
- data/gems/server/ext/itsi_server/src/server/bind_protocol.rs +0 -37
- data/gems/server/ext/itsi_server/src/server/io_stream.rs +0 -104
- data/gems/server/ext/itsi_server/src/server/itsi_server.rs +0 -288
- data/gems/server/ext/itsi_server/src/server/lifecycle_event.rs +0 -9
- data/gems/server/ext/itsi_server/src/server/listener.rs +0 -318
- data/gems/server/ext/itsi_server/src/server/mod.rs +0 -11
- data/gems/server/ext/itsi_server/src/server/process_worker.rs +0 -203
- data/gems/server/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +0 -260
- data/gems/server/ext/itsi_server/src/server/serve_strategy/mod.rs +0 -27
- data/gems/server/ext/itsi_server/src/server/serve_strategy/single_mode.rs +0 -276
- data/gems/server/ext/itsi_server/src/server/signal.rs +0 -74
- data/gems/server/ext/itsi_server/src/server/thread_worker.rs +0 -399
- data/gems/server/ext/itsi_server/src/server/tls/locked_dir_cache.rs +0 -132
- data/gems/server/ext/itsi_server/src/server/tls.rs +0 -265
- data/gems/server/ext/itsi_tracing/Cargo.lock +0 -274
- data/gems/server/ext/itsi_tracing/Cargo.toml +0 -16
- data/gems/server/ext/itsi_tracing/src/lib.rs +0 -58
- data/gems/server/lib/itsi/server/options_dsl.rb +0 -401
- data/gems/server/lib/itsi/stream_io.rb +0 -38
- data/location_dsl.rb +0 -381
- data/sandbox/itsi_sandbox_rails/.kamal/hooks/docker-setup.sample +0 -3
- data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-app-boot.sample +0 -3
- data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-deploy.sample +0 -14
- data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-proxy-reboot.sample +0 -3
- data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-app-boot.sample +0 -3
- data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-build.sample +0 -51
- data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-connect.sample +0 -47
- data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-deploy.sample +0 -109
- data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-proxy-reboot.sample +0 -3
- data/sandbox/itsi_sandbox_rails/.kamal/secrets +0 -17
- data/sandbox/itsi_sandbox_rails/bin/dev +0 -2
- data/sandbox/itsi_sandbox_rails/bin/jobs +0 -6
- data/sandbox/itsi_sandbox_rails/bin/kamal +0 -27
- data/sandbox/itsi_sandbox_rails/bin/thrust +0 -5
- data/sandbox/itsi_sandbox_rails/config/cache.yml +0 -16
- data/sandbox/itsi_sandbox_rails/config/deploy.yml +0 -116
- data/sandbox/itsi_sandbox_rails/config/queue.yml +0 -18
- data/sandbox/itsi_sandbox_rails/config/recurring.yml +0 -10
- data/sandbox/itsi_sandbox_rails/db/cable_schema.rb +0 -11
- data/sandbox/itsi_sandbox_rails/db/cache_schema.rb +0 -14
- data/sandbox/itsi_sandbox_rails/db/queue_schema.rb +0 -129
- data/sandbox/itsi_sandbox_rails/public/400.html +0 -114
- data/sandbox/itsi_sandbox_rails/test/fixtures/posts.yml +0 -9
- data/sandbox/itsi_sandbox_rails/test/models/post_test.rb +0 -7
- /data/{sandbox/itsi_sandbox_rails/script/.keep → crates/_index.md} +0 -0
- /data/gems/server/lib/itsi/{index.html → server/default_app/index.html} +0 -0
@@ -1,50 +0,0 @@
|
|
1
|
-
[package]
|
2
|
-
name = "itsi-server"
|
3
|
-
version = "0.1.0"
|
4
|
-
edition = "2021"
|
5
|
-
authors = ["Wouter Coppieters <wc@pico.net.nz>"]
|
6
|
-
license = "MIT"
|
7
|
-
publish = false
|
8
|
-
|
9
|
-
[lib]
|
10
|
-
crate-type = ["cdylib"]
|
11
|
-
|
12
|
-
[dependencies]
|
13
|
-
magnus = { version = "0.7.1", features = ["bytes", "rb-sys"] }
|
14
|
-
itsi_tracing = { path = "../itsi_tracing" }
|
15
|
-
itsi_rb_helpers = { path = "../itsi_rb_helpers" }
|
16
|
-
itsi_error = { path = "../itsi_error" }
|
17
|
-
socket2 = "0.5.8"
|
18
|
-
parking_lot = "0.12.3"
|
19
|
-
rustls-pemfile = "2.2.0"
|
20
|
-
tokio-rustls = "0.26.2"
|
21
|
-
bytes = "1.3"
|
22
|
-
tokio-rustls-acme = "0.6.0"
|
23
|
-
rcgen = { version = "0.13.2", features = ["x509-parser", "pem"] }
|
24
|
-
base64 = "0.22.1"
|
25
|
-
http-body-util = "0.1.2"
|
26
|
-
hyper = { version = "1.5.0", features = ["full", "server", "http1", "http2"] }
|
27
|
-
tokio = { version = "1.44.1", features = ["full"] }
|
28
|
-
hyper-util = { version = "0.1.10", features = ["full"] }
|
29
|
-
derive_more = { version = "2.0.1", features = ["debug"] }
|
30
|
-
http = "1.3.1"
|
31
|
-
crossbeam = "0.8.4"
|
32
|
-
futures = "0.3.31"
|
33
|
-
nix = { version = "0.29.0", features = ["socket", "uio", "signal"] }
|
34
|
-
pin-project = "1.1.9"
|
35
|
-
rb-sys = "0.9.111"
|
36
|
-
tracing = "0.1.41"
|
37
|
-
tokio-util = "0.7.13"
|
38
|
-
tokio-stream = "0.1.17"
|
39
|
-
httparse = "1.10.1"
|
40
|
-
async-channel = "2.3.1"
|
41
|
-
tempfile = "3.18.0"
|
42
|
-
sysinfo = "0.33.1"
|
43
|
-
rustls = "0.23.23"
|
44
|
-
fs2 = "0.4.3"
|
45
|
-
ring = "0.17.14"
|
46
|
-
async-trait = "0.1.87"
|
47
|
-
dirs = "6.0.0"
|
48
|
-
regex = "1.11.1"
|
49
|
-
route-recognizer = "0.3.1"
|
50
|
-
fnv = "1.0.7"
|
@@ -1,104 +0,0 @@
|
|
1
|
-
use bytes::Bytes;
|
2
|
-
use magnus::{IntoValue, Ruby, Value};
|
3
|
-
use std::io::{Result as IoResult, Write};
|
4
|
-
use std::path::PathBuf;
|
5
|
-
use tempfile::NamedTempFile;
|
6
|
-
|
7
|
-
const THRESHOLD: usize = 1024 * 1024; // 1 MB
|
8
|
-
|
9
|
-
/// An container that holds data in memory if it’s small, or in a temporary file on disk if it exceeds THRESHOLD.
|
10
|
-
/// Used for providing Rack input data.
|
11
|
-
pub enum BigBytes {
|
12
|
-
InMemory(Vec<u8>),
|
13
|
-
OnDisk(NamedTempFile),
|
14
|
-
}
|
15
|
-
|
16
|
-
/// The result type for reading the contents of a `BigBytes` value.
|
17
|
-
pub enum BigBytesReadResult {
|
18
|
-
/// When the data is stored in memory, returns the cached bytes.
|
19
|
-
InMemory(Vec<u8>),
|
20
|
-
/// When the data is stored on disk, returns the path to the temporary file.
|
21
|
-
OnDisk(PathBuf),
|
22
|
-
}
|
23
|
-
|
24
|
-
impl BigBytes {
|
25
|
-
/// Creates a new, empty BigBytes instance (initially in memory).
|
26
|
-
pub fn new() -> Self {
|
27
|
-
BigBytes::InMemory(Vec::new())
|
28
|
-
}
|
29
|
-
|
30
|
-
/// Reads the entire contents that have been written.
|
31
|
-
///
|
32
|
-
/// - If stored in memory, returns a clone of the bytes.
|
33
|
-
/// - If stored on disk, returns the file path of the temporary file.
|
34
|
-
pub fn read(&self) -> IoResult<BigBytesReadResult> {
|
35
|
-
match self {
|
36
|
-
BigBytes::InMemory(vec) => Ok(BigBytesReadResult::InMemory(vec.clone())),
|
37
|
-
BigBytes::OnDisk(temp_file) => {
|
38
|
-
// Flush to be safe, then return the file path.
|
39
|
-
temp_file.as_file().sync_all()?;
|
40
|
-
Ok(BigBytesReadResult::OnDisk(temp_file.path().to_path_buf()))
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
pub fn as_value(&self) -> Value {
|
46
|
-
match self {
|
47
|
-
BigBytes::InMemory(bytes) => {
|
48
|
-
let bytes = Bytes::from(bytes.to_owned());
|
49
|
-
bytes.into_value()
|
50
|
-
}
|
51
|
-
BigBytes::OnDisk(path) => {
|
52
|
-
let ruby = Ruby::get().unwrap();
|
53
|
-
let rarray = ruby.ary_new();
|
54
|
-
rarray.push(path.path().to_str().unwrap().into_value()).ok();
|
55
|
-
rarray.into_value()
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
impl Drop for BigBytes {
|
62
|
-
fn drop(&mut self) {
|
63
|
-
match self {
|
64
|
-
BigBytes::InMemory(_) => {}
|
65
|
-
BigBytes::OnDisk(path) => {
|
66
|
-
let _ = std::fs::remove_file(path);
|
67
|
-
}
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
impl Default for BigBytes {
|
73
|
-
fn default() -> Self {
|
74
|
-
Self::new()
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
impl Write for BigBytes {
|
79
|
-
fn write(&mut self, buf: &[u8]) -> IoResult<usize> {
|
80
|
-
match self {
|
81
|
-
BigBytes::InMemory(vec) => {
|
82
|
-
// Check if writing the new bytes would exceed the threshold.
|
83
|
-
if vec.len() + buf.len() > THRESHOLD {
|
84
|
-
let mut tmp = NamedTempFile::new()?;
|
85
|
-
tmp.write_all(vec)?;
|
86
|
-
tmp.write_all(buf)?;
|
87
|
-
*self = BigBytes::OnDisk(tmp);
|
88
|
-
Ok(buf.len())
|
89
|
-
} else {
|
90
|
-
vec.extend_from_slice(buf);
|
91
|
-
Ok(buf.len())
|
92
|
-
}
|
93
|
-
}
|
94
|
-
BigBytes::OnDisk(tmp_file) => tmp_file.write(buf),
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
fn flush(&mut self) -> IoResult<()> {
|
99
|
-
match self {
|
100
|
-
BigBytes::InMemory(_) => Ok(()),
|
101
|
-
BigBytes::OnDisk(tmp_file) => tmp_file.flush(),
|
102
|
-
}
|
103
|
-
}
|
104
|
-
}
|
@@ -1,122 +0,0 @@
|
|
1
|
-
use super::big_bytes::BigBytes;
|
2
|
-
use bytes::Bytes;
|
3
|
-
use futures::executor::block_on;
|
4
|
-
use http_body_util::{BodyDataStream, BodyExt};
|
5
|
-
use hyper::body::Incoming;
|
6
|
-
use magnus::{error::Result as MagnusResult, scan_args, IntoValue, RString, Ruby, Value};
|
7
|
-
use parking_lot::Mutex;
|
8
|
-
use std::sync::{
|
9
|
-
atomic::{self, AtomicBool},
|
10
|
-
Arc,
|
11
|
-
};
|
12
|
-
use tokio_stream::StreamExt;
|
13
|
-
|
14
|
-
#[magnus::wrap(class = "Itsi::BodyProxy", free_immediately, size)]
|
15
|
-
#[derive(Debug, Clone)]
|
16
|
-
pub struct ItsiBodyProxy {
|
17
|
-
pub incoming: Arc<Mutex<BodyDataStream<Incoming>>>,
|
18
|
-
pub closed: Arc<AtomicBool>,
|
19
|
-
pub buf: Arc<Mutex<Vec<u8>>>,
|
20
|
-
}
|
21
|
-
|
22
|
-
pub enum ItsiBody {
|
23
|
-
Buffered(BigBytes),
|
24
|
-
Stream(ItsiBodyProxy),
|
25
|
-
}
|
26
|
-
|
27
|
-
impl ItsiBody {
|
28
|
-
pub fn into_value(&self) -> Value {
|
29
|
-
match self {
|
30
|
-
ItsiBody::Buffered(bytes) => bytes.as_value(),
|
31
|
-
ItsiBody::Stream(proxy) => proxy.clone().into_value(),
|
32
|
-
}
|
33
|
-
}
|
34
|
-
}
|
35
|
-
impl ItsiBodyProxy {
|
36
|
-
pub fn new(incoming: Incoming) -> Self {
|
37
|
-
ItsiBodyProxy {
|
38
|
-
incoming: Arc::new(Mutex::new(incoming.into_data_stream())),
|
39
|
-
closed: Arc::new(AtomicBool::new(false)),
|
40
|
-
buf: Arc::new(Mutex::new(vec![])),
|
41
|
-
}
|
42
|
-
}
|
43
|
-
/// Read up to the next line-break OR EOF
|
44
|
-
pub fn gets(&self) -> MagnusResult<Option<Bytes>> {
|
45
|
-
self.verify_open()?;
|
46
|
-
let mut stream = self.incoming.lock();
|
47
|
-
let mut buf = self.buf.lock();
|
48
|
-
while !buf.contains(&b'\n') {
|
49
|
-
if let Some(chunk) = block_on(stream.next()) {
|
50
|
-
let chunk = chunk.map_err(|err| {
|
51
|
-
magnus::Error::new(
|
52
|
-
magnus::exception::exception(),
|
53
|
-
format!("Error reading body {:?}", err),
|
54
|
-
)
|
55
|
-
})?;
|
56
|
-
buf.extend_from_slice(&chunk);
|
57
|
-
} else {
|
58
|
-
break;
|
59
|
-
}
|
60
|
-
}
|
61
|
-
if let Some(pos) = buf.iter().position(|&x| x == b'\n') {
|
62
|
-
let line = buf.drain(..=pos).collect::<Vec<u8>>();
|
63
|
-
Ok(Some(line.into()))
|
64
|
-
} else if !buf.is_empty() {
|
65
|
-
let line = buf.drain(..).collect::<Vec<u8>>();
|
66
|
-
Ok(Some(line.into()))
|
67
|
-
} else {
|
68
|
-
Ok(None)
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
pub fn read(&self, args: &[Value]) -> MagnusResult<Option<RString>> {
|
73
|
-
self.verify_open()?;
|
74
|
-
let scanned =
|
75
|
-
scan_args::scan_args::<(), (Option<usize>, Option<RString>), (), (), (), ()>(args)?;
|
76
|
-
let (length, mut buffer) = scanned.optional;
|
77
|
-
let mut stream = self.incoming.lock();
|
78
|
-
let mut buf = self.buf.lock();
|
79
|
-
|
80
|
-
while length.is_none_or(|target_length| buf.len() < target_length) {
|
81
|
-
if let Some(chunk) = block_on(stream.next()) {
|
82
|
-
let chunk = chunk.map_err(|err| {
|
83
|
-
magnus::Error::new(
|
84
|
-
magnus::exception::exception(),
|
85
|
-
format!("Error reading body {:?}", err),
|
86
|
-
)
|
87
|
-
})?;
|
88
|
-
buf.extend_from_slice(&chunk);
|
89
|
-
} else if length.is_some() {
|
90
|
-
return Ok(None);
|
91
|
-
} else {
|
92
|
-
break;
|
93
|
-
}
|
94
|
-
}
|
95
|
-
let output_string = buffer.take().unwrap_or(RString::buf_new(buf.len()));
|
96
|
-
output_string.cat(buf.clone());
|
97
|
-
buf.clear();
|
98
|
-
Ok(Some(output_string))
|
99
|
-
}
|
100
|
-
|
101
|
-
/// Equivalent to calling gets and yielding it, until we reach EOF
|
102
|
-
pub fn each(ruby: &Ruby, rbself: &Self) -> MagnusResult<()> {
|
103
|
-
let proc = ruby.block_proc()?;
|
104
|
-
while let Some(str) = rbself.gets()? {
|
105
|
-
proc.call::<_, Value>((str,))?;
|
106
|
-
}
|
107
|
-
Ok(())
|
108
|
-
}
|
109
|
-
|
110
|
-
fn verify_open(&self) -> MagnusResult<()> {
|
111
|
-
if self.closed.load(atomic::Ordering::SeqCst) {
|
112
|
-
return Err(magnus::Error::new(
|
113
|
-
magnus::exception::exception(),
|
114
|
-
"Body stream is closed",
|
115
|
-
));
|
116
|
-
}
|
117
|
-
Ok(())
|
118
|
-
}
|
119
|
-
pub fn close(&self) {
|
120
|
-
self.closed.store(true, atomic::Ordering::SeqCst);
|
121
|
-
}
|
122
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
use std::{
|
2
|
-
env::{var, VarError},
|
3
|
-
path::PathBuf,
|
4
|
-
sync::LazyLock,
|
5
|
-
};
|
6
|
-
|
7
|
-
type StringVar = LazyLock<String>;
|
8
|
-
type MaybeStringVar = LazyLock<Result<String, VarError>>;
|
9
|
-
type PathVar = LazyLock<PathBuf>;
|
10
|
-
|
11
|
-
/// ACME Configuration for auto-generating production certificates
|
12
|
-
/// *ITSI_ACME_CACHE_DIR* - Directory to store cached certificates
|
13
|
-
/// so that these are not regenerated every time the server starts
|
14
|
-
pub static ITSI_ACME_CACHE_DIR: StringVar = LazyLock::new(|| {
|
15
|
-
var("ITSI_ACME_CACHE_DIR").unwrap_or_else(|_| "./.rustls_acme_cache".to_string())
|
16
|
-
});
|
17
|
-
|
18
|
-
/// *ITSI_ACME_CONTACT_EMAIL* - Contact Email address to provide to ACME server during certificate renewal
|
19
|
-
pub static ITSI_ACME_CONTACT_EMAIL: MaybeStringVar =
|
20
|
-
LazyLock::new(|| var("ITSI_ACME_CONTACT_EMAIL"));
|
21
|
-
|
22
|
-
/// *ITSI_ACME_CA_PEM_PATH* - Optional CA Pem path, used for testing with non-trusted CAs for certifcate generation.
|
23
|
-
pub static ITSI_ACME_CA_PEM_PATH: MaybeStringVar = LazyLock::new(|| var("ITSI_ACME_CA_PEM_PATH"));
|
24
|
-
|
25
|
-
/// *ITSI_ACME_DIRECTORY_URL* - Directory URL to use for ACME certificate generation.
|
26
|
-
pub static ITSI_ACME_DIRECTORY_URL: StringVar = LazyLock::new(|| {
|
27
|
-
var("ITSI_ACME_DIRECTORY_URL")
|
28
|
-
.unwrap_or_else(|_| "https://acme-v02.api.letsencrypt.org/directory".to_string())
|
29
|
-
});
|
30
|
-
|
31
|
-
/// *ITSI_ACME_LOCK_FILE_NAME* - Name of the lock file used to prevent concurrent certificate generation.
|
32
|
-
pub static ITSI_ACME_LOCK_FILE_NAME: StringVar =
|
33
|
-
LazyLock::new(|| var("ITSI_ACME_LOCK_FILE_NAME").unwrap_or(".acme.lock".to_string()));
|
34
|
-
|
35
|
-
pub static ITSI_LOCAL_CA_DIR: PathVar = LazyLock::new(|| {
|
36
|
-
var("ITSI_LOCAL_CA_DIR")
|
37
|
-
.map(PathBuf::from)
|
38
|
-
.unwrap_or_else(|_| {
|
39
|
-
dirs::home_dir()
|
40
|
-
.expect("Failed to find HOME directory when initializing ITSI_LOCAL_CA_DIR")
|
41
|
-
.join(".itsi")
|
42
|
-
})
|
43
|
-
});
|
@@ -1,180 +0,0 @@
|
|
1
|
-
use body_proxy::itsi_body_proxy::ItsiBodyProxy;
|
2
|
-
use magnus::{
|
3
|
-
error::Result, function, method, value::Lazy, Module, Object, RClass, RHash, RModule, Ruby,
|
4
|
-
};
|
5
|
-
use regex::{Regex, RegexSet};
|
6
|
-
use request::itsi_request::ItsiRequest;
|
7
|
-
use response::itsi_response::ItsiResponse;
|
8
|
-
use server::{itsi_server::Server, signal::reset_signal_handlers};
|
9
|
-
use tracing::*;
|
10
|
-
|
11
|
-
pub mod body_proxy;
|
12
|
-
pub mod env;
|
13
|
-
pub mod request;
|
14
|
-
pub mod response;
|
15
|
-
pub mod server;
|
16
|
-
|
17
|
-
pub static ITSI_MODULE: Lazy<RModule> = Lazy::new(|ruby| ruby.define_module("Itsi").unwrap());
|
18
|
-
pub static ITSI_SERVER: Lazy<RClass> = Lazy::new(|ruby| {
|
19
|
-
ruby.get_inner(&ITSI_MODULE)
|
20
|
-
.define_class("Server", ruby.class_object())
|
21
|
-
.unwrap()
|
22
|
-
});
|
23
|
-
pub static ITSI_REQUEST: Lazy<RClass> = Lazy::new(|ruby| {
|
24
|
-
ruby.get_inner(&ITSI_MODULE)
|
25
|
-
.define_class("Request", ruby.class_object())
|
26
|
-
.unwrap()
|
27
|
-
});
|
28
|
-
|
29
|
-
pub static ITSI_RESPONSE: Lazy<RClass> = Lazy::new(|ruby| {
|
30
|
-
ruby.get_inner(&ITSI_MODULE)
|
31
|
-
.define_class("Response", ruby.class_object())
|
32
|
-
.unwrap()
|
33
|
-
});
|
34
|
-
|
35
|
-
pub static ITSI_BODY_PROXY: Lazy<RClass> = Lazy::new(|ruby| {
|
36
|
-
ruby.get_inner(&ITSI_MODULE)
|
37
|
-
.define_class("BodyProxy", ruby.class_object())
|
38
|
-
.unwrap()
|
39
|
-
});
|
40
|
-
|
41
|
-
pub static ITSI_SERVER_SCHEDULER_TASK: Lazy<RClass> = Lazy::new(|ruby| {
|
42
|
-
ruby.get_inner(&ITSI_MODULE)
|
43
|
-
.define_class("ServerSchedulerTask", ruby.class_object())
|
44
|
-
.unwrap()
|
45
|
-
});
|
46
|
-
|
47
|
-
pub fn log_debug(msg: String) {
|
48
|
-
debug!(msg);
|
49
|
-
}
|
50
|
-
pub fn log_info(msg: String) {
|
51
|
-
info!(msg);
|
52
|
-
}
|
53
|
-
pub fn log_warn(msg: String) {
|
54
|
-
warn!(msg);
|
55
|
-
}
|
56
|
-
pub fn log_error(msg: String) {
|
57
|
-
error!(msg);
|
58
|
-
}
|
59
|
-
|
60
|
-
const ROUTES: [&str; 39] = [
|
61
|
-
r"(?-u)^/organisations/(?<organisation_id>\d+)/users/(?<user_id>\d+)$",
|
62
|
-
r"(?-u)^/projects/(?<project_id>\d+)/tasks/(?<task_id>\d+)$",
|
63
|
-
r"(?-u)^/products/(?<product_id>\d+)(?:/reviews/(?<review_id>\d+))?$",
|
64
|
-
r"(?-u)^/orders/(?<order_id>\d+)/items(?:/(?<item_id>\d+))?$",
|
65
|
-
r"(?-u)^/posts/(?<post_id>\d+)/comments(?:/(?<comment_id>\d+))?$",
|
66
|
-
r"(?-u)^/teams/(?<team_id>\d+)(?:/members/(?<member_id>\d+))?$",
|
67
|
-
r"(?-u)^/categories/(?<category_id>\d+)/subcategories(?:/(?<subcategory_id>\d+))?$",
|
68
|
-
r"(?-u)^/departments/(?<department_id>\d+)/employees/(?<employee_id>\d+)$",
|
69
|
-
r"(?-u)^/events/(?<event_id>\d+)(?:/sessions/(?<session_id>\d+))?$",
|
70
|
-
r"(?-u)^/invoices/(?<invoice_id>\d+)/payments(?:/(?<payment_id>\d+))?$",
|
71
|
-
r"(?-u)^/tickets/(?<ticket_id>\d+)(?:/responses/(?<response_id>\d+))?$",
|
72
|
-
r"(?-u)^/forums/(?<forum_id>\d+)(?:/threads/(?<thread_id>\d+))?$",
|
73
|
-
r"(?-u)^/subscriptions/(?<subscription_id>\d+)/plans(?:/(?<plan_id>\d+))?$",
|
74
|
-
r"(?-u)^/profiles/(?<profile_id>\d+)/settings$",
|
75
|
-
r"(?-u)^/organizations/(?<organization_id>\d+)/billing(?:/(?<billing_id>\d+))?$",
|
76
|
-
r"(?-u)^/vendors/(?<vendor_id>\d+)/products(?:/(?<product_id>\d+))?$",
|
77
|
-
r"(?-u)^/courses/(?<course_id>\d+)/modules(?:/(?<module_id>\d+))?$",
|
78
|
-
r"(?-u)^/accounts/(?<account_id>\d+)(?:/transactions/(?<transaction_id>\d+))?$",
|
79
|
-
r"(?-u)^/warehouses/(?<warehouse_id>\d+)/inventory(?:/(?<inventory_id>\d+))?$",
|
80
|
-
r"(?-u)^/campaigns/(?<campaign_id>\d+)/ads(?:/(?<ad_id>\d+))?$",
|
81
|
-
r"(?-u)^/applications/(?<application_id>\d+)/stages(?:/(?<stage_id>\d+))?$",
|
82
|
-
r"(?-u)^/notifications/(?<notification_id>\d+)$",
|
83
|
-
r"(?-u)^/albums/(?<album_id>\d+)/photos(?:/(?<photo_id>\d+))?$",
|
84
|
-
r"(?-u)^/news/(?<news_id>\d+)/articles(?:/(?<article_id>\d+))?$",
|
85
|
-
r"(?-u)^/libraries/(?<library_id>\d+)/books(?:/(?<book_id>\d+))?$",
|
86
|
-
r"(?-u)^/universities/(?<university_id>\d+)/students(?:/(?<student_id>\d+))?$",
|
87
|
-
r"(?-u)^/banks/(?<bank_id>\d+)/branches(?:/(?<branch_id>\d+))?$",
|
88
|
-
r"(?-u)^/vehicles/(?<vehicle_id>\d+)/services(?:/(?<service_id>\d+))?$",
|
89
|
-
r"(?-u)^/hotels/(?<hotel_id>\d+)/rooms(?:/(?<room_id>\d+))?$",
|
90
|
-
r"(?-u)^/doctors/(?<doctor_id>\d+)/appointments(?:/(?<appointment_id>\d+))?$",
|
91
|
-
r"(?-u)^/gyms/(?<gym_id>\d+)/memberships(?:/(?<membership_id>\d+))?$",
|
92
|
-
r"(?-u)^/restaurants/(?<restaurant_id>\d+)/menus(?:/(?<menu_id>\d+))?$",
|
93
|
-
r"(?-u)^/parks/(?<park_id>\d+)/events(?:/(?<event_id>\d+))?$",
|
94
|
-
r"(?-u)^/theaters/(?<theater_id>\d+)/shows(?:/(?<show_id>\d+))?$",
|
95
|
-
r"(?-u)^/museums/(?<museum_id>\d+)/exhibits(?:/(?<exhibit_id>\d+))?$",
|
96
|
-
r"(?-u)^/stadiums/(?<stadium_id>\d+)/games(?:/(?<game_id>\d+))?$",
|
97
|
-
r"(?-u)^/schools/(?<school_id>\d+)/classes(?:/(?<class_id>\d+))?$",
|
98
|
-
r"(?-u)^/clubs/(?<club_id>\d+)/events(?:/(?<event_id>\d+))?$",
|
99
|
-
r"(?-u)^/festivals/(?<festival_id>\d+)/tickets(?:/(?<ticket_id>\d+))?$",
|
100
|
-
];
|
101
|
-
use std::sync::LazyLock;
|
102
|
-
|
103
|
-
static REGEX_SET: LazyLock<RegexSet> = LazyLock::new(|| RegexSet::new(ROUTES).unwrap());
|
104
|
-
static REGEXES: LazyLock<Vec<Regex>> =
|
105
|
-
LazyLock::new(|| ROUTES.iter().map(|&r| Regex::new(r).unwrap()).collect());
|
106
|
-
|
107
|
-
fn match_route(input: String) -> Result<Option<(usize, Option<RHash>)>> {
|
108
|
-
if let Some(index) = REGEX_SET.matches(&input).iter().next() {
|
109
|
-
let regex = ®EXES[index];
|
110
|
-
if let Some(captures) = regex.captures(&input) {
|
111
|
-
let params = RHash::with_capacity(captures.len());
|
112
|
-
for name in regex.capture_names().flatten() {
|
113
|
-
if let Some(value) = captures.name(name) {
|
114
|
-
params.aset(name, value.as_str()).ok();
|
115
|
-
}
|
116
|
-
}
|
117
|
-
return Ok(Some((index, Some(params))));
|
118
|
-
}
|
119
|
-
return Ok(Some((index, None)));
|
120
|
-
}
|
121
|
-
Ok(None)
|
122
|
-
}
|
123
|
-
|
124
|
-
#[magnus::init]
|
125
|
-
fn init(ruby: &Ruby) -> Result<()> {
|
126
|
-
itsi_tracing::init();
|
127
|
-
rustls::crypto::aws_lc_rs::default_provider()
|
128
|
-
.install_default()
|
129
|
-
.ok();
|
130
|
-
|
131
|
-
let itsi = ruby.get_inner(&ITSI_MODULE);
|
132
|
-
itsi.define_singleton_method("match_route", function!(match_route, 1))?;
|
133
|
-
itsi.define_singleton_method("log_debug", function!(log_debug, 1))?;
|
134
|
-
itsi.define_singleton_method("log_info", function!(log_info, 1))?;
|
135
|
-
itsi.define_singleton_method("log_warn", function!(log_warn, 1))?;
|
136
|
-
itsi.define_singleton_method("log_error", function!(log_error, 1))?;
|
137
|
-
|
138
|
-
let server = ruby.get_inner(&ITSI_SERVER);
|
139
|
-
server.define_singleton_method("new", function!(Server::new, -1))?;
|
140
|
-
server.define_singleton_method("reset_signal_handlers", function!(reset_signal_handlers, 0))?;
|
141
|
-
server.define_method("start", method!(Server::start, 0))?;
|
142
|
-
server.define_method("stop", method!(Server::stop, 0))?;
|
143
|
-
|
144
|
-
let request = ruby.get_inner(&ITSI_REQUEST);
|
145
|
-
request.define_method("path", method!(ItsiRequest::path, 0))?;
|
146
|
-
request.define_method("script_name", method!(ItsiRequest::script_name, 0))?;
|
147
|
-
request.define_method("query_string", method!(ItsiRequest::query_string, 0))?;
|
148
|
-
request.define_method("method", method!(ItsiRequest::method, 0))?;
|
149
|
-
request.define_method("version", method!(ItsiRequest::version, 0))?;
|
150
|
-
request.define_method("rack_protocol", method!(ItsiRequest::rack_protocol, 0))?;
|
151
|
-
request.define_method("host", method!(ItsiRequest::host, 0))?;
|
152
|
-
request.define_method("headers", method!(ItsiRequest::headers, 0))?;
|
153
|
-
request.define_method("scheme", method!(ItsiRequest::scheme, 0))?;
|
154
|
-
request.define_method("remote_addr", method!(ItsiRequest::remote_addr, 0))?;
|
155
|
-
request.define_method("port", method!(ItsiRequest::port, 0))?;
|
156
|
-
request.define_method("body", method!(ItsiRequest::body, 0))?;
|
157
|
-
request.define_method("response", method!(ItsiRequest::response, 0))?;
|
158
|
-
request.define_method("json?", method!(ItsiRequest::is_json, 0))?;
|
159
|
-
request.define_method("html?", method!(ItsiRequest::is_html, 0))?;
|
160
|
-
|
161
|
-
let body_proxy = ruby.get_inner(&ITSI_BODY_PROXY);
|
162
|
-
body_proxy.define_method("gets", method!(ItsiBodyProxy::gets, 0))?;
|
163
|
-
body_proxy.define_method("each", method!(ItsiBodyProxy::each, 0))?;
|
164
|
-
body_proxy.define_method("read", method!(ItsiBodyProxy::read, -1))?;
|
165
|
-
body_proxy.define_method("close", method!(ItsiBodyProxy::close, 0))?;
|
166
|
-
|
167
|
-
let response = ruby.get_inner(&ITSI_RESPONSE);
|
168
|
-
response.define_method("add_header", method!(ItsiResponse::add_header, 2))?;
|
169
|
-
response.define_method("status=", method!(ItsiResponse::set_status, 1))?;
|
170
|
-
response.define_method("send_frame", method!(ItsiResponse::send_frame, 1))?;
|
171
|
-
response.define_method("send_and_close", method!(ItsiResponse::send_and_close, 1))?;
|
172
|
-
response.define_method("close_write", method!(ItsiResponse::close_write, 0))?;
|
173
|
-
response.define_method("close_read", method!(ItsiResponse::close_read, 0))?;
|
174
|
-
response.define_method("close", method!(ItsiResponse::close, 0))?;
|
175
|
-
response.define_method("hijack", method!(ItsiResponse::hijack, 1))?;
|
176
|
-
response.define_method("json?", method!(ItsiResponse::is_json, 0))?;
|
177
|
-
response.define_method("html?", method!(ItsiResponse::is_html, 0))?;
|
178
|
-
|
179
|
-
Ok(())
|
180
|
-
}
|