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,298 +0,0 @@
|
|
1
|
-
use crate::{
|
2
|
-
body_proxy::{
|
3
|
-
big_bytes::BigBytes,
|
4
|
-
itsi_body_proxy::{ItsiBody, ItsiBodyProxy},
|
5
|
-
},
|
6
|
-
response::itsi_response::ItsiResponse,
|
7
|
-
server::{
|
8
|
-
itsi_server::{RequestJob, Server},
|
9
|
-
listener::{ListenerInfo, SockAddr},
|
10
|
-
serve_strategy::single_mode::RunningPhase,
|
11
|
-
},
|
12
|
-
};
|
13
|
-
use bytes::Bytes;
|
14
|
-
use derive_more::Debug;
|
15
|
-
use futures::StreamExt;
|
16
|
-
use http::{request::Parts, HeaderValue, Response, StatusCode};
|
17
|
-
use http_body_util::{combinators::BoxBody, BodyExt, Empty};
|
18
|
-
use hyper::{body::Incoming, Request};
|
19
|
-
use itsi_error::from::CLIENT_CONNECTION_CLOSED;
|
20
|
-
use itsi_rb_helpers::print_rb_backtrace;
|
21
|
-
use itsi_tracing::{debug, error};
|
22
|
-
use magnus::{
|
23
|
-
error::{ErrorType, Result as MagnusResult},
|
24
|
-
Error,
|
25
|
-
};
|
26
|
-
use magnus::{
|
27
|
-
value::{LazyId, Opaque, ReprValue},
|
28
|
-
RClass, Ruby, Value,
|
29
|
-
};
|
30
|
-
use std::{convert::Infallible, fmt, io::Write, sync::Arc, time::Instant};
|
31
|
-
use tokio::sync::{
|
32
|
-
mpsc::{self},
|
33
|
-
watch,
|
34
|
-
};
|
35
|
-
static ID_CALL: LazyId = LazyId::new("call");
|
36
|
-
static ID_MESSAGE: LazyId = LazyId::new("message");
|
37
|
-
|
38
|
-
#[derive(Debug)]
|
39
|
-
#[magnus::wrap(class = "Itsi::Request", free_immediately, size)]
|
40
|
-
pub struct ItsiRequest {
|
41
|
-
pub parts: Parts,
|
42
|
-
#[debug(skip)]
|
43
|
-
pub body: ItsiBody,
|
44
|
-
pub remote_addr: String,
|
45
|
-
pub version: String,
|
46
|
-
#[debug(skip)]
|
47
|
-
pub(crate) listener: Arc<ListenerInfo>,
|
48
|
-
#[debug(skip)]
|
49
|
-
pub server: Arc<Server>,
|
50
|
-
pub response: ItsiResponse,
|
51
|
-
pub start: Instant,
|
52
|
-
pub content_type: String,
|
53
|
-
}
|
54
|
-
|
55
|
-
impl fmt::Display for ItsiRequest {
|
56
|
-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
57
|
-
write!(
|
58
|
-
f,
|
59
|
-
"{} {} {}",
|
60
|
-
self.version().unwrap(),
|
61
|
-
self.method().unwrap(),
|
62
|
-
self.path().unwrap()
|
63
|
-
)
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
impl ItsiRequest {
|
68
|
-
pub fn is_connection_closed_err(ruby: &Ruby, err: &Error) -> bool {
|
69
|
-
match err.error_type() {
|
70
|
-
ErrorType::Jump(_) => false,
|
71
|
-
ErrorType::Error(_, _) => false,
|
72
|
-
ErrorType::Exception(exception) => {
|
73
|
-
exception.is_kind_of(ruby.exception_eof_error())
|
74
|
-
&& err
|
75
|
-
.value()
|
76
|
-
.map(|v| {
|
77
|
-
v.funcall::<_, _, String>(*ID_MESSAGE, ())
|
78
|
-
.unwrap_or("".to_string())
|
79
|
-
.eq(CLIENT_CONNECTION_CLOSED)
|
80
|
-
})
|
81
|
-
.unwrap_or(false)
|
82
|
-
}
|
83
|
-
}
|
84
|
-
}
|
85
|
-
|
86
|
-
pub fn is_json(&self) -> bool {
|
87
|
-
self.content_type.eq("application/json")
|
88
|
-
}
|
89
|
-
|
90
|
-
pub fn is_html(&self) -> bool {
|
91
|
-
self.content_type.eq("text/html")
|
92
|
-
}
|
93
|
-
|
94
|
-
pub fn process(
|
95
|
-
self,
|
96
|
-
ruby: &Ruby,
|
97
|
-
server: RClass,
|
98
|
-
app: Opaque<Value>,
|
99
|
-
) -> magnus::error::Result<()> {
|
100
|
-
let req = format!("{}", self);
|
101
|
-
let response = self.response.clone();
|
102
|
-
let start = self.start;
|
103
|
-
debug!("{} Started", req);
|
104
|
-
let result = server.funcall::<_, _, Value>(*ID_CALL, (app, self));
|
105
|
-
if let Err(err) = result {
|
106
|
-
Self::internal_error(ruby, response, err);
|
107
|
-
}
|
108
|
-
debug!("{} Finished in {:?}", req, start.elapsed());
|
109
|
-
|
110
|
-
Ok(())
|
111
|
-
}
|
112
|
-
|
113
|
-
pub fn internal_error(ruby: &Ruby, response: ItsiResponse, err: Error) {
|
114
|
-
if Self::is_connection_closed_err(ruby, &err) {
|
115
|
-
debug!("Connection closed by client");
|
116
|
-
response.close();
|
117
|
-
} else if let Some(rb_err) = err.value() {
|
118
|
-
print_rb_backtrace(rb_err);
|
119
|
-
response.internal_server_error(err.to_string());
|
120
|
-
} else {
|
121
|
-
response.internal_server_error(err.to_string());
|
122
|
-
}
|
123
|
-
}
|
124
|
-
|
125
|
-
pub fn error(self, message: String) {
|
126
|
-
self.response.internal_server_error(message);
|
127
|
-
}
|
128
|
-
|
129
|
-
pub(crate) async fn process_request(
|
130
|
-
hyper_request: Request<Incoming>,
|
131
|
-
sender: async_channel::Sender<RequestJob>,
|
132
|
-
server: Arc<Server>,
|
133
|
-
listener: Arc<ListenerInfo>,
|
134
|
-
addr: SockAddr,
|
135
|
-
shutdown_rx: watch::Receiver<RunningPhase>,
|
136
|
-
) -> itsi_error::Result<Response<BoxBody<Bytes, Infallible>>> {
|
137
|
-
let (request, mut receiver) = ItsiRequest::new(hyper_request, addr, server, listener).await;
|
138
|
-
|
139
|
-
let response = request.response.clone();
|
140
|
-
match sender.send(RequestJob::ProcessRequest(request)).await {
|
141
|
-
Err(err) => {
|
142
|
-
error!("Error occurred: {}", err);
|
143
|
-
let mut response = Response::new(BoxBody::new(Empty::new()));
|
144
|
-
*response.status_mut() = StatusCode::BAD_REQUEST;
|
145
|
-
Ok(response)
|
146
|
-
}
|
147
|
-
_ => match receiver.recv().await {
|
148
|
-
Some(first_frame) => Ok(response.build(first_frame, receiver, shutdown_rx).await),
|
149
|
-
None => Ok(response.build(None, receiver, shutdown_rx).await),
|
150
|
-
},
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
pub(crate) async fn new(
|
155
|
-
request: Request<Incoming>,
|
156
|
-
sock_addr: SockAddr,
|
157
|
-
server: Arc<Server>,
|
158
|
-
listener: Arc<ListenerInfo>,
|
159
|
-
) -> (ItsiRequest, mpsc::Receiver<Option<Bytes>>) {
|
160
|
-
let (parts, body) = request.into_parts();
|
161
|
-
let body = if server.stream_body.is_some_and(|f| f) {
|
162
|
-
ItsiBody::Stream(ItsiBodyProxy::new(body))
|
163
|
-
} else {
|
164
|
-
let mut body_bytes = BigBytes::new();
|
165
|
-
let mut stream = body.into_data_stream();
|
166
|
-
while let Some(chunk) = stream.next().await {
|
167
|
-
let byte_array = chunk.unwrap().to_vec();
|
168
|
-
body_bytes.write_all(&byte_array).unwrap();
|
169
|
-
}
|
170
|
-
ItsiBody::Buffered(body_bytes)
|
171
|
-
};
|
172
|
-
let response_channel = mpsc::channel::<Option<Bytes>>(100);
|
173
|
-
(
|
174
|
-
Self {
|
175
|
-
remote_addr: sock_addr.to_string(),
|
176
|
-
body,
|
177
|
-
server,
|
178
|
-
listener,
|
179
|
-
version: format!("{:?}", &parts.version),
|
180
|
-
response: ItsiResponse::new(
|
181
|
-
parts.clone(),
|
182
|
-
response_channel.0,
|
183
|
-
parts
|
184
|
-
.headers
|
185
|
-
.get("Accept")
|
186
|
-
.unwrap_or(&HeaderValue::from_static("text/html"))
|
187
|
-
.to_str()
|
188
|
-
.unwrap()
|
189
|
-
.to_string(),
|
190
|
-
),
|
191
|
-
start: Instant::now(),
|
192
|
-
content_type: parts
|
193
|
-
.headers
|
194
|
-
.get("Content-Type")
|
195
|
-
.unwrap_or(&HeaderValue::from_static(
|
196
|
-
"application/x-www-form-urlencoded",
|
197
|
-
))
|
198
|
-
.to_str()
|
199
|
-
.unwrap()
|
200
|
-
.to_string(),
|
201
|
-
parts,
|
202
|
-
},
|
203
|
-
response_channel.1,
|
204
|
-
)
|
205
|
-
}
|
206
|
-
|
207
|
-
pub(crate) fn path(&self) -> MagnusResult<&str> {
|
208
|
-
Ok(self
|
209
|
-
.parts
|
210
|
-
.uri
|
211
|
-
.path()
|
212
|
-
.strip_prefix(&self.server.script_name)
|
213
|
-
.unwrap_or(self.parts.uri.path()))
|
214
|
-
}
|
215
|
-
|
216
|
-
pub(crate) fn script_name(&self) -> MagnusResult<&str> {
|
217
|
-
Ok(&self.server.script_name)
|
218
|
-
}
|
219
|
-
|
220
|
-
pub(crate) fn query_string(&self) -> MagnusResult<&str> {
|
221
|
-
Ok(self.parts.uri.query().unwrap_or(""))
|
222
|
-
}
|
223
|
-
|
224
|
-
pub(crate) fn method(&self) -> MagnusResult<&str> {
|
225
|
-
Ok(self.parts.method.as_str())
|
226
|
-
}
|
227
|
-
|
228
|
-
pub(crate) fn version(&self) -> MagnusResult<&str> {
|
229
|
-
Ok(&self.version)
|
230
|
-
}
|
231
|
-
|
232
|
-
pub(crate) fn rack_protocol(&self) -> MagnusResult<Vec<&str>> {
|
233
|
-
Ok(self
|
234
|
-
.parts
|
235
|
-
.headers
|
236
|
-
.get("upgrade")
|
237
|
-
.or_else(|| self.parts.headers.get("protocol"))
|
238
|
-
.map(|value| {
|
239
|
-
value
|
240
|
-
.to_str()
|
241
|
-
.unwrap_or("")
|
242
|
-
.split(',')
|
243
|
-
.map(|s| s.trim())
|
244
|
-
.collect::<Vec<&str>>()
|
245
|
-
})
|
246
|
-
.unwrap_or_else(|| vec!["http"]))
|
247
|
-
}
|
248
|
-
|
249
|
-
pub(crate) fn host(&self) -> MagnusResult<String> {
|
250
|
-
Ok(self
|
251
|
-
.parts
|
252
|
-
.uri
|
253
|
-
.host()
|
254
|
-
.map(|host| host.to_string())
|
255
|
-
.unwrap_or_else(|| self.listener.host.clone()))
|
256
|
-
}
|
257
|
-
|
258
|
-
pub(crate) fn scheme(&self) -> MagnusResult<String> {
|
259
|
-
Ok(self
|
260
|
-
.parts
|
261
|
-
.uri
|
262
|
-
.scheme()
|
263
|
-
.map(|scheme| scheme.to_string())
|
264
|
-
.unwrap_or_else(|| self.listener.scheme.clone()))
|
265
|
-
}
|
266
|
-
|
267
|
-
pub(crate) fn headers(&self) -> MagnusResult<Vec<(String, &str)>> {
|
268
|
-
Ok(self
|
269
|
-
.parts
|
270
|
-
.headers
|
271
|
-
.iter()
|
272
|
-
.map(|(hn, hv)| {
|
273
|
-
let key = match hn.as_str() {
|
274
|
-
"content-length" => "CONTENT_LENGTH".to_string(),
|
275
|
-
"content-type" => "CONTENT_TYPE".to_string(),
|
276
|
-
_ => format!("HTTP_{}", hn.as_str().to_uppercase().replace("-", "_")),
|
277
|
-
};
|
278
|
-
(key, hv.to_str().unwrap_or(""))
|
279
|
-
})
|
280
|
-
.collect())
|
281
|
-
}
|
282
|
-
|
283
|
-
pub(crate) fn remote_addr(&self) -> MagnusResult<&str> {
|
284
|
-
Ok(&self.remote_addr)
|
285
|
-
}
|
286
|
-
|
287
|
-
pub(crate) fn port(&self) -> MagnusResult<u16> {
|
288
|
-
Ok(self.parts.uri.port_u16().unwrap_or(self.listener.port))
|
289
|
-
}
|
290
|
-
|
291
|
-
pub(crate) fn body(&self) -> MagnusResult<Value> {
|
292
|
-
Ok(self.body.into_value())
|
293
|
-
}
|
294
|
-
|
295
|
-
pub(crate) fn response(&self) -> MagnusResult<ItsiResponse> {
|
296
|
-
Ok(self.response.clone())
|
297
|
-
}
|
298
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
pub mod itsi_request;
|
@@ -1 +0,0 @@
|
|
1
|
-
pub mod itsi_response;
|
@@ -1,288 +0,0 @@
|
|
1
|
-
use super::{
|
2
|
-
bind::Bind,
|
3
|
-
listener::Listener,
|
4
|
-
serve_strategy::{cluster_mode::ClusterMode, single_mode::SingleMode},
|
5
|
-
signal::{
|
6
|
-
clear_signal_handlers, reset_signal_handlers, send_shutdown_event, SIGNAL_HANDLER_CHANNEL,
|
7
|
-
},
|
8
|
-
};
|
9
|
-
use crate::{request::itsi_request::ItsiRequest, server::serve_strategy::ServeStrategy};
|
10
|
-
use derive_more::Debug;
|
11
|
-
use itsi_rb_helpers::{call_without_gvl, HeapVal, HeapValue};
|
12
|
-
use itsi_tracing::{error, run_silently};
|
13
|
-
use magnus::{
|
14
|
-
block::Proc,
|
15
|
-
error::Result,
|
16
|
-
scan_args::{get_kwargs, scan_args, Args, KwArgs, ScanArgsKw, ScanArgsOpt, ScanArgsRequired},
|
17
|
-
value::ReprValue,
|
18
|
-
ArgList, RArray, RHash, Ruby, Symbol, Value,
|
19
|
-
};
|
20
|
-
use parking_lot::{Mutex, RwLock};
|
21
|
-
use std::{cmp::max, collections::HashMap, ops::Deref, sync::Arc};
|
22
|
-
use tracing::{info, instrument};
|
23
|
-
|
24
|
-
static DEFAULT_BIND: &str = "http://localhost:3000";
|
25
|
-
|
26
|
-
#[magnus::wrap(class = "Itsi::Server", free_immediately, size)]
|
27
|
-
#[derive(Clone)]
|
28
|
-
pub struct Server {
|
29
|
-
pub config: Arc<ServerConfig>,
|
30
|
-
}
|
31
|
-
|
32
|
-
impl Deref for Server {
|
33
|
-
type Target = ServerConfig;
|
34
|
-
|
35
|
-
fn deref(&self) -> &Self::Target {
|
36
|
-
&self.config
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
#[derive(Debug)]
|
41
|
-
pub struct ServerConfig {
|
42
|
-
#[debug(skip)]
|
43
|
-
pub app: HeapVal,
|
44
|
-
#[allow(unused)]
|
45
|
-
pub workers: u8,
|
46
|
-
#[allow(unused)]
|
47
|
-
pub threads: u8,
|
48
|
-
#[allow(unused)]
|
49
|
-
pub shutdown_timeout: f64,
|
50
|
-
pub script_name: String,
|
51
|
-
pub(crate) binds: Mutex<Vec<Bind>>,
|
52
|
-
#[debug(skip)]
|
53
|
-
pub hooks: HashMap<String, HeapValue<Proc>>,
|
54
|
-
pub scheduler_class: Option<String>,
|
55
|
-
pub stream_body: Option<bool>,
|
56
|
-
pub worker_memory_limit: Option<u64>,
|
57
|
-
#[debug(skip)]
|
58
|
-
pub(crate) strategy: RwLock<Option<ServeStrategy>>,
|
59
|
-
pub silence: bool,
|
60
|
-
pub oob_gc_responses_threshold: Option<u64>,
|
61
|
-
}
|
62
|
-
|
63
|
-
#[derive(Debug)]
|
64
|
-
pub enum RequestJob {
|
65
|
-
ProcessRequest(ItsiRequest),
|
66
|
-
Shutdown,
|
67
|
-
}
|
68
|
-
|
69
|
-
fn extract_args<Req, Opt, Splat>(
|
70
|
-
scan_args: &Args<(), (), (), (), RHash, ()>,
|
71
|
-
primaries: &[&str],
|
72
|
-
rest: &[&str],
|
73
|
-
) -> Result<KwArgs<Req, Opt, Splat>>
|
74
|
-
where
|
75
|
-
Req: ScanArgsRequired,
|
76
|
-
Opt: ScanArgsOpt,
|
77
|
-
Splat: ScanArgsKw,
|
78
|
-
{
|
79
|
-
let symbols: Vec<Symbol> = primaries
|
80
|
-
.iter()
|
81
|
-
.chain(rest.iter())
|
82
|
-
.map(|&name| Symbol::new(name))
|
83
|
-
.collect();
|
84
|
-
|
85
|
-
let hash = scan_args
|
86
|
-
.keywords
|
87
|
-
.funcall::<_, _, RHash>("slice", symbols.into_arg_list_with(&Ruby::get().unwrap()))
|
88
|
-
.unwrap();
|
89
|
-
|
90
|
-
get_kwargs(hash, primaries, rest)
|
91
|
-
}
|
92
|
-
|
93
|
-
impl Server {
|
94
|
-
#[instrument(
|
95
|
-
name = "Itsi",
|
96
|
-
parent=None,
|
97
|
-
skip(args),
|
98
|
-
fields(workers = 1, threads = 1, shutdown_timeout = 5)
|
99
|
-
)]
|
100
|
-
pub fn new(args: &[Value]) -> Result<Self> {
|
101
|
-
let scan_args: Args<(), (), (), (), RHash, ()> = scan_args(args)?;
|
102
|
-
|
103
|
-
type Args1 = KwArgs<
|
104
|
-
(Value,),
|
105
|
-
(
|
106
|
-
// Workers
|
107
|
-
Option<u8>,
|
108
|
-
// Threads
|
109
|
-
Option<u8>,
|
110
|
-
// Shutdown Timeout
|
111
|
-
Option<f64>,
|
112
|
-
// Script Name
|
113
|
-
Option<String>,
|
114
|
-
// Binds
|
115
|
-
Option<Vec<String>>,
|
116
|
-
// Stream Body
|
117
|
-
Option<bool>,
|
118
|
-
),
|
119
|
-
(),
|
120
|
-
>;
|
121
|
-
|
122
|
-
type Args2 = KwArgs<
|
123
|
-
(),
|
124
|
-
(
|
125
|
-
// Hooks
|
126
|
-
Option<RHash>,
|
127
|
-
// Scheduler Class
|
128
|
-
Option<String>,
|
129
|
-
// Worker Memory Limit
|
130
|
-
Option<u64>,
|
131
|
-
// Out-of-band GC Responses Threshold
|
132
|
-
Option<u64>,
|
133
|
-
// Silence
|
134
|
-
Option<bool>,
|
135
|
-
),
|
136
|
-
(),
|
137
|
-
>;
|
138
|
-
|
139
|
-
let args1: Args1 = extract_args(
|
140
|
-
&scan_args,
|
141
|
-
&["app"],
|
142
|
-
&[
|
143
|
-
"workers",
|
144
|
-
"threads",
|
145
|
-
"shutdown_timeout",
|
146
|
-
"script_name",
|
147
|
-
"binds",
|
148
|
-
"stream_body",
|
149
|
-
],
|
150
|
-
)?;
|
151
|
-
|
152
|
-
let args2: Args2 = extract_args(
|
153
|
-
&scan_args,
|
154
|
-
&[],
|
155
|
-
&[
|
156
|
-
"hooks",
|
157
|
-
"scheduler_class",
|
158
|
-
"worker_memory_limit",
|
159
|
-
"oob_gc_responses_threshold",
|
160
|
-
"silence",
|
161
|
-
],
|
162
|
-
)?;
|
163
|
-
|
164
|
-
let hooks = args2
|
165
|
-
.optional
|
166
|
-
.0
|
167
|
-
.map(|rhash| -> Result<HashMap<String, HeapValue<Proc>>> {
|
168
|
-
let mut hook_map: HashMap<String, HeapValue<Proc>> = HashMap::new();
|
169
|
-
for pair in rhash.enumeratorize::<_, ()>("each", ()) {
|
170
|
-
if let Some(pair_value) = RArray::from_value(pair?) {
|
171
|
-
if let (Ok(key), Ok(value)) =
|
172
|
-
(pair_value.entry::<Value>(0), pair_value.entry::<Proc>(1))
|
173
|
-
{
|
174
|
-
hook_map.insert(key.to_string(), HeapValue::from(value));
|
175
|
-
}
|
176
|
-
}
|
177
|
-
}
|
178
|
-
Ok(hook_map)
|
179
|
-
})
|
180
|
-
.transpose()?
|
181
|
-
.unwrap_or_default();
|
182
|
-
|
183
|
-
let config = ServerConfig {
|
184
|
-
app: HeapVal::from(args1.required.0),
|
185
|
-
workers: max(args1.optional.0.unwrap_or(1), 1),
|
186
|
-
threads: max(args1.optional.1.unwrap_or(1), 1),
|
187
|
-
shutdown_timeout: args1.optional.2.unwrap_or(5.0),
|
188
|
-
script_name: args1.optional.3.unwrap_or("".to_string()),
|
189
|
-
binds: Mutex::new(
|
190
|
-
args1
|
191
|
-
.optional
|
192
|
-
.4
|
193
|
-
.unwrap_or_else(|| vec![DEFAULT_BIND.to_string()])
|
194
|
-
.into_iter()
|
195
|
-
.map(|s| s.parse())
|
196
|
-
.collect::<itsi_error::Result<Vec<Bind>>>()?,
|
197
|
-
),
|
198
|
-
stream_body: args1.optional.5,
|
199
|
-
hooks,
|
200
|
-
scheduler_class: args2.optional.1.clone(),
|
201
|
-
worker_memory_limit: args2.optional.2,
|
202
|
-
strategy: RwLock::new(None),
|
203
|
-
oob_gc_responses_threshold: args2.optional.3,
|
204
|
-
silence: args2.optional.4.is_some_and(|s| s),
|
205
|
-
};
|
206
|
-
|
207
|
-
if !config.silence {
|
208
|
-
if let Some(scheduler_class) = args2.optional.1 {
|
209
|
-
info!(scheduler_class, fiber_scheduler = true);
|
210
|
-
} else {
|
211
|
-
info!(fiber_scheduler = false);
|
212
|
-
}
|
213
|
-
}
|
214
|
-
|
215
|
-
Ok(Server {
|
216
|
-
config: Arc::new(config),
|
217
|
-
})
|
218
|
-
}
|
219
|
-
|
220
|
-
#[instrument(name = "Bind", skip_all, fields(binds=format!("{:?}", self.config.binds.lock())))]
|
221
|
-
pub(crate) fn build_listeners(&self) -> Result<Vec<Listener>> {
|
222
|
-
let listeners = self
|
223
|
-
.config
|
224
|
-
.binds
|
225
|
-
.lock()
|
226
|
-
.iter()
|
227
|
-
.cloned()
|
228
|
-
.map(Listener::try_from)
|
229
|
-
.collect::<std::result::Result<Vec<Listener>, _>>()?
|
230
|
-
.into_iter()
|
231
|
-
.collect::<Vec<_>>();
|
232
|
-
info!("Bound {:?} listeners", listeners.len());
|
233
|
-
Ok(listeners)
|
234
|
-
}
|
235
|
-
|
236
|
-
pub(crate) fn build_strategy(self) -> Result<()> {
|
237
|
-
let listeners = self.build_listeners()?;
|
238
|
-
let server = Arc::new(self);
|
239
|
-
let server_clone = server.clone();
|
240
|
-
|
241
|
-
let strategy = if server.config.workers == 1 {
|
242
|
-
ServeStrategy::Single(Arc::new(SingleMode::new(
|
243
|
-
server,
|
244
|
-
listeners,
|
245
|
-
SIGNAL_HANDLER_CHANNEL.0.clone(),
|
246
|
-
)?))
|
247
|
-
} else {
|
248
|
-
ServeStrategy::Cluster(Arc::new(ClusterMode::new(
|
249
|
-
server,
|
250
|
-
listeners,
|
251
|
-
SIGNAL_HANDLER_CHANNEL.0.clone(),
|
252
|
-
)))
|
253
|
-
};
|
254
|
-
|
255
|
-
*server_clone.strategy.write() = Some(strategy);
|
256
|
-
Ok(())
|
257
|
-
}
|
258
|
-
|
259
|
-
pub fn stop(&self) -> Result<()> {
|
260
|
-
send_shutdown_event();
|
261
|
-
Ok(())
|
262
|
-
}
|
263
|
-
|
264
|
-
pub fn start(&self) -> Result<()> {
|
265
|
-
if self.silence {
|
266
|
-
run_silently(|| self.build_and_run_strategy())
|
267
|
-
} else {
|
268
|
-
self.build_and_run_strategy()
|
269
|
-
}
|
270
|
-
}
|
271
|
-
|
272
|
-
fn build_and_run_strategy(&self) -> Result<()> {
|
273
|
-
reset_signal_handlers();
|
274
|
-
let rself = self.clone();
|
275
|
-
call_without_gvl(move || -> Result<()> {
|
276
|
-
rself.clone().build_strategy()?;
|
277
|
-
if let Err(e) = rself.strategy.read().as_ref().unwrap().run() {
|
278
|
-
error!("Error running server: {}", e);
|
279
|
-
rself.strategy.read().as_ref().unwrap().stop()?;
|
280
|
-
}
|
281
|
-
Ok(())
|
282
|
-
})?;
|
283
|
-
clear_signal_handlers();
|
284
|
-
self.strategy.write().take();
|
285
|
-
info!("Server stopped");
|
286
|
-
Ok(())
|
287
|
-
}
|
288
|
-
}
|