itsi-server 0.1.1 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/CODE_OF_CONDUCT.md +7 -0
  4. data/Cargo.lock +3937 -0
  5. data/Cargo.toml +7 -0
  6. data/README.md +4 -0
  7. data/Rakefile +8 -1
  8. data/_index.md +6 -0
  9. data/exe/itsi +141 -46
  10. data/ext/itsi_error/Cargo.toml +3 -0
  11. data/ext/itsi_error/src/lib.rs +98 -24
  12. data/ext/itsi_error/target/debug/build/clang-sys-da71b0344e568175/out/common.rs +355 -0
  13. data/ext/itsi_error/target/debug/build/clang-sys-da71b0344e568175/out/dynamic.rs +276 -0
  14. data/ext/itsi_error/target/debug/build/clang-sys-da71b0344e568175/out/macros.rs +49 -0
  15. data/ext/itsi_error/target/debug/build/rb-sys-49f554618693db24/out/bindings-0.9.110-mri-arm64-darwin23-3.4.2.rs +8865 -0
  16. data/ext/itsi_error/target/debug/incremental/itsi_error-1mmt5sux7jb0i/s-h510z7m8v9-0bxu7yd.lock +0 -0
  17. data/ext/itsi_error/target/debug/incremental/itsi_error-2vn3jey74oiw0/s-h5113n0e7e-1v5qzs6.lock +0 -0
  18. data/ext/itsi_error/target/debug/incremental/itsi_error-37uv9dicz7awp/s-h510ykifhe-0tbnep2.lock +0 -0
  19. data/ext/itsi_error/target/debug/incremental/itsi_error-37uv9dicz7awp/s-h510yyocpj-0tz7ug7.lock +0 -0
  20. data/ext/itsi_error/target/debug/incremental/itsi_error-37uv9dicz7awp/s-h510z0xc8g-14ol18k.lock +0 -0
  21. data/ext/itsi_error/target/debug/incremental/itsi_error-3g5qf4y7d54uj/s-h5113n0e7d-1trk8on.lock +0 -0
  22. data/ext/itsi_error/target/debug/incremental/itsi_error-3lpfftm45d3e2/s-h510z7m8r3-1pxp20o.lock +0 -0
  23. data/ext/itsi_error/target/debug/incremental/itsi_error-3o4qownhl3d7n/s-h510ykifek-1uxasnk.lock +0 -0
  24. data/ext/itsi_error/target/debug/incremental/itsi_error-3o4qownhl3d7n/s-h510yyocki-11u37qm.lock +0 -0
  25. data/ext/itsi_error/target/debug/incremental/itsi_error-3o4qownhl3d7n/s-h510z0xc93-0pmy0zm.lock +0 -0
  26. data/ext/itsi_instrument_entry/Cargo.toml +15 -0
  27. data/ext/itsi_instrument_entry/src/lib.rs +31 -0
  28. data/ext/itsi_rb_helpers/Cargo.toml +3 -0
  29. data/ext/itsi_rb_helpers/src/heap_value.rs +139 -0
  30. data/ext/itsi_rb_helpers/src/lib.rs +140 -10
  31. data/ext/itsi_rb_helpers/target/debug/build/clang-sys-da71b0344e568175/out/common.rs +355 -0
  32. data/ext/itsi_rb_helpers/target/debug/build/clang-sys-da71b0344e568175/out/dynamic.rs +276 -0
  33. data/ext/itsi_rb_helpers/target/debug/build/clang-sys-da71b0344e568175/out/macros.rs +49 -0
  34. data/ext/itsi_rb_helpers/target/debug/build/rb-sys-eb9ed4ff3a60f995/out/bindings-0.9.110-mri-arm64-darwin23-3.4.2.rs +8865 -0
  35. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-040pxg6yhb3g3/s-h5113n7a1b-03bwlt4.lock +0 -0
  36. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-131g1u4dzkt1a/s-h51113xnh3-1eik1ip.lock +0 -0
  37. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-131g1u4dzkt1a/s-h5111704jj-0g4rj8x.lock +0 -0
  38. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-1q2d3drtxrzs5/s-h5113n79yl-0bxcqc5.lock +0 -0
  39. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-374a9h7ovycj0/s-h51113xoox-10de2hp.lock +0 -0
  40. data/ext/itsi_rb_helpers/target/debug/incremental/itsi_rb_helpers-374a9h7ovycj0/s-h5111704w7-0vdq7gq.lock +0 -0
  41. data/ext/itsi_scheduler/Cargo.toml +24 -0
  42. data/ext/itsi_scheduler/src/itsi_scheduler/io_helpers.rs +56 -0
  43. data/ext/itsi_scheduler/src/itsi_scheduler/io_waiter.rs +44 -0
  44. data/ext/itsi_scheduler/src/itsi_scheduler/timer.rs +44 -0
  45. data/ext/itsi_scheduler/src/itsi_scheduler.rs +308 -0
  46. data/ext/itsi_scheduler/src/lib.rs +38 -0
  47. data/ext/itsi_server/Cargo.lock +2956 -0
  48. data/ext/itsi_server/Cargo.toml +72 -14
  49. data/ext/itsi_server/extconf.rb +1 -1
  50. data/ext/itsi_server/src/default_responses/html/401.html +68 -0
  51. data/ext/itsi_server/src/default_responses/html/403.html +68 -0
  52. data/ext/itsi_server/src/default_responses/html/404.html +68 -0
  53. data/ext/itsi_server/src/default_responses/html/413.html +71 -0
  54. data/ext/itsi_server/src/default_responses/html/429.html +68 -0
  55. data/ext/itsi_server/src/default_responses/html/500.html +71 -0
  56. data/ext/itsi_server/src/default_responses/html/502.html +71 -0
  57. data/ext/itsi_server/src/default_responses/html/503.html +68 -0
  58. data/ext/itsi_server/src/default_responses/html/504.html +69 -0
  59. data/ext/itsi_server/src/default_responses/html/index.html +238 -0
  60. data/ext/itsi_server/src/default_responses/json/401.json +6 -0
  61. data/ext/itsi_server/src/default_responses/json/403.json +6 -0
  62. data/ext/itsi_server/src/default_responses/json/404.json +6 -0
  63. data/ext/itsi_server/src/default_responses/json/413.json +6 -0
  64. data/ext/itsi_server/src/default_responses/json/429.json +6 -0
  65. data/ext/itsi_server/src/default_responses/json/500.json +6 -0
  66. data/ext/itsi_server/src/default_responses/json/502.json +6 -0
  67. data/ext/itsi_server/src/default_responses/json/503.json +6 -0
  68. data/ext/itsi_server/src/default_responses/json/504.json +6 -0
  69. data/ext/itsi_server/src/default_responses/mod.rs +11 -0
  70. data/ext/itsi_server/src/env.rs +43 -0
  71. data/ext/itsi_server/src/lib.rs +132 -40
  72. data/ext/itsi_server/src/prelude.rs +2 -0
  73. data/ext/itsi_server/src/ruby_types/itsi_body_proxy/big_bytes.rs +109 -0
  74. data/ext/itsi_server/src/ruby_types/itsi_body_proxy/mod.rs +143 -0
  75. data/ext/itsi_server/src/ruby_types/itsi_grpc_call.rs +344 -0
  76. data/ext/itsi_server/src/ruby_types/itsi_grpc_response_stream/mod.rs +264 -0
  77. data/ext/itsi_server/src/ruby_types/itsi_http_request.rs +345 -0
  78. data/ext/itsi_server/src/ruby_types/itsi_http_response.rs +391 -0
  79. data/ext/itsi_server/src/ruby_types/itsi_server/file_watcher.rs +225 -0
  80. data/ext/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +375 -0
  81. data/ext/itsi_server/src/ruby_types/itsi_server.rs +83 -0
  82. data/ext/itsi_server/src/ruby_types/mod.rs +48 -0
  83. data/ext/itsi_server/src/server/binds/bind.rs +201 -0
  84. data/ext/itsi_server/src/server/binds/bind_protocol.rs +37 -0
  85. data/ext/itsi_server/src/server/binds/listener.rs +432 -0
  86. data/ext/itsi_server/src/server/binds/mod.rs +4 -0
  87. data/ext/itsi_server/src/server/binds/tls/locked_dir_cache.rs +132 -0
  88. data/ext/itsi_server/src/server/binds/tls.rs +270 -0
  89. data/ext/itsi_server/src/server/byte_frame.rs +32 -0
  90. data/ext/itsi_server/src/server/http_message_types.rs +97 -0
  91. data/ext/itsi_server/src/server/io_stream.rs +105 -0
  92. data/ext/itsi_server/src/server/lifecycle_event.rs +12 -0
  93. data/ext/itsi_server/src/server/middleware_stack/middleware.rs +165 -0
  94. data/ext/itsi_server/src/server/middleware_stack/middlewares/allow_list.rs +56 -0
  95. data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_api_key.rs +87 -0
  96. data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_basic.rs +86 -0
  97. data/ext/itsi_server/src/server/middleware_stack/middlewares/auth_jwt.rs +285 -0
  98. data/ext/itsi_server/src/server/middleware_stack/middlewares/cache_control.rs +142 -0
  99. data/ext/itsi_server/src/server/middleware_stack/middlewares/compression.rs +289 -0
  100. data/ext/itsi_server/src/server/middleware_stack/middlewares/cors.rs +292 -0
  101. data/ext/itsi_server/src/server/middleware_stack/middlewares/deny_list.rs +55 -0
  102. data/ext/itsi_server/src/server/middleware_stack/middlewares/error_response/default_responses.rs +190 -0
  103. data/ext/itsi_server/src/server/middleware_stack/middlewares/error_response.rs +157 -0
  104. data/ext/itsi_server/src/server/middleware_stack/middlewares/etag.rs +195 -0
  105. data/ext/itsi_server/src/server/middleware_stack/middlewares/header_interpretation.rs +82 -0
  106. data/ext/itsi_server/src/server/middleware_stack/middlewares/intrusion_protection.rs +201 -0
  107. data/ext/itsi_server/src/server/middleware_stack/middlewares/log_requests.rs +82 -0
  108. data/ext/itsi_server/src/server/middleware_stack/middlewares/max_body.rs +47 -0
  109. data/ext/itsi_server/src/server/middleware_stack/middlewares/mod.rs +87 -0
  110. data/ext/itsi_server/src/server/middleware_stack/middlewares/proxy.rs +414 -0
  111. data/ext/itsi_server/src/server/middleware_stack/middlewares/rate_limit.rs +131 -0
  112. data/ext/itsi_server/src/server/middleware_stack/middlewares/redirect.rs +76 -0
  113. data/ext/itsi_server/src/server/middleware_stack/middlewares/request_headers.rs +44 -0
  114. data/ext/itsi_server/src/server/middleware_stack/middlewares/response_headers.rs +36 -0
  115. data/ext/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +126 -0
  116. data/ext/itsi_server/src/server/middleware_stack/middlewares/static_assets.rs +180 -0
  117. data/ext/itsi_server/src/server/middleware_stack/middlewares/static_response.rs +55 -0
  118. data/ext/itsi_server/src/server/middleware_stack/middlewares/string_rewrite.rs +163 -0
  119. data/ext/itsi_server/src/server/middleware_stack/middlewares/token_source.rs +12 -0
  120. data/ext/itsi_server/src/server/middleware_stack/mod.rs +347 -0
  121. data/ext/itsi_server/src/server/mod.rs +12 -5
  122. data/ext/itsi_server/src/server/process_worker.rs +247 -0
  123. data/ext/itsi_server/src/server/request_job.rs +11 -0
  124. data/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +342 -0
  125. data/ext/itsi_server/src/server/serve_strategy/mod.rs +30 -0
  126. data/ext/itsi_server/src/server/serve_strategy/single_mode.rs +421 -0
  127. data/ext/itsi_server/src/server/signal.rs +76 -0
  128. data/ext/itsi_server/src/server/size_limited_incoming.rs +101 -0
  129. data/ext/itsi_server/src/server/thread_worker.rs +475 -0
  130. data/ext/itsi_server/src/services/cache_store.rs +74 -0
  131. data/ext/itsi_server/src/services/itsi_http_service.rs +239 -0
  132. data/ext/itsi_server/src/services/mime_types.rs +1416 -0
  133. data/ext/itsi_server/src/services/mod.rs +6 -0
  134. data/ext/itsi_server/src/services/password_hasher.rs +83 -0
  135. data/ext/itsi_server/src/services/rate_limiter.rs +569 -0
  136. data/ext/itsi_server/src/services/static_file_server.rs +1324 -0
  137. data/ext/itsi_tracing/Cargo.toml +5 -0
  138. data/ext/itsi_tracing/src/lib.rs +315 -7
  139. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-0994n8rpvvt9m/s-h510hfz1f6-1kbycmq.lock +0 -0
  140. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-0bob7bf4yq34i/s-h5113125h5-0lh4rag.lock +0 -0
  141. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2fcodulrxbbxo/s-h510h2infk-0hp5kjw.lock +0 -0
  142. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2iak63r1woi1l/s-h510h2in4q-0kxfzw1.lock +0 -0
  143. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2kk4qj9gn5dg2/s-h5113124kv-0enwon2.lock +0 -0
  144. data/ext/itsi_tracing/target/debug/incremental/itsi_tracing-2mwo0yas7dtw4/s-h510hfz1ha-1udgpei.lock +0 -0
  145. data/lib/itsi/http_request/response_status_shortcodes.rb +74 -0
  146. data/lib/itsi/http_request.rb +186 -0
  147. data/lib/itsi/http_response.rb +41 -0
  148. data/lib/itsi/passfile.rb +109 -0
  149. data/lib/itsi/server/config/dsl.rb +565 -0
  150. data/lib/itsi/server/config.rb +166 -0
  151. data/lib/itsi/server/default_app/default_app.rb +34 -0
  152. data/lib/itsi/server/default_app/index.html +115 -0
  153. data/lib/itsi/server/default_config/Itsi-rackup.rb +119 -0
  154. data/lib/itsi/server/default_config/Itsi.rb +107 -0
  155. data/lib/itsi/server/grpc/grpc_call.rb +246 -0
  156. data/lib/itsi/server/grpc/grpc_interface.rb +100 -0
  157. data/lib/itsi/server/grpc/reflection/v1/reflection_pb.rb +26 -0
  158. data/lib/itsi/server/grpc/reflection/v1/reflection_services_pb.rb +122 -0
  159. data/lib/itsi/server/rack/handler/itsi.rb +27 -0
  160. data/lib/itsi/server/rack_interface.rb +94 -0
  161. data/lib/itsi/server/route_tester.rb +107 -0
  162. data/lib/itsi/server/scheduler_interface.rb +21 -0
  163. data/lib/itsi/server/scheduler_mode.rb +10 -0
  164. data/lib/itsi/server/signal_trap.rb +29 -0
  165. data/lib/itsi/server/typed_handlers/param_parser.rb +200 -0
  166. data/lib/itsi/server/typed_handlers/source_parser.rb +55 -0
  167. data/lib/itsi/server/typed_handlers.rb +17 -0
  168. data/lib/itsi/server/version.rb +1 -1
  169. data/lib/itsi/server.rb +160 -9
  170. data/lib/itsi/standard_headers.rb +86 -0
  171. data/lib/ruby_lsp/itsi/addon.rb +111 -0
  172. data/lib/shell_completions/completions.rb +26 -0
  173. metadata +182 -25
  174. data/ext/itsi_server/src/request/itsi_request.rs +0 -143
  175. data/ext/itsi_server/src/request/mod.rs +0 -1
  176. data/ext/itsi_server/src/server/bind.rs +0 -138
  177. data/ext/itsi_server/src/server/itsi_ca/itsi_ca.crt +0 -32
  178. data/ext/itsi_server/src/server/itsi_ca/itsi_ca.key +0 -52
  179. data/ext/itsi_server/src/server/itsi_server.rs +0 -182
  180. data/ext/itsi_server/src/server/listener.rs +0 -218
  181. data/ext/itsi_server/src/server/tls.rs +0 -138
  182. data/ext/itsi_server/src/server/transfer_protocol.rs +0 -23
  183. data/ext/itsi_server/src/stream_writer/mod.rs +0 -21
  184. data/lib/itsi/request.rb +0 -39
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Itsi
4
+ class Server
5
+ module Config
6
+ require_relative "config/dsl"
7
+ require_relative "default_app/default_app"
8
+
9
+ ITSI_DEFAULT_CONFIG_FILE = "Itsi.rb"
10
+
11
+ def self.prep_reexec!
12
+ @argv ||= ARGV[0...ARGV.index("--listeners")]
13
+
14
+ auto_suppress_fork_darwin_fork_safety_warnings = [
15
+ ENV["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"].nil? || ENV["PGGSSENCMODE"].nil?,
16
+ RUBY_PLATFORM =~ /darwin/,
17
+ !ENV.key?("ITSI_DISABLE_AUTO_DISABLE_DARWIN_FORK_SAFETY_WARNINGS"),
18
+ $PROGRAM_NAME =~ /itsi$/
19
+ ].all?
20
+ return unless auto_suppress_fork_darwin_fork_safety_warnings
21
+
22
+ env = ENV.to_h.merge("OBJC_DISABLE_INITIALIZE_FORK_SAFETY" => "YES", "PGGSSENCMODE" => "disable")
23
+ if ENV["BUNDLE_BIN_PATH"]
24
+ exec env, "bundle", "exec", $PROGRAM_NAME, *@argv
25
+ else
26
+ exec env, $PROGRAM_NAME, *@argv
27
+ end
28
+ end
29
+
30
+ # The configuration used when launching the Itsi server are evaluated in the following precedence:
31
+ # 1. CLI Args.
32
+ # 2. Itsi.rb file.
33
+ # 3. Default values.
34
+ def self.build_config(args, config_file_path, builder_proc = nil)
35
+ args.transform_keys!(&:to_sym)
36
+ itsifile_config = \
37
+ if builder_proc
38
+ DSL.evaluate(&builder_proc)
39
+ elsif args[:static]
40
+ DSL.evaluate do
41
+ location "/" do
42
+ allow_list allowed_patterns: ['127.0.0.1']
43
+ rate_limit key: 'address', store_config: 'in_memory', requests: 2, seconds: 5
44
+ etag type: 'strong', algorithm: 'md5', min_body_size: 1024 * 1024
45
+ compress min_size: 1024 * 1024, level: 'fastest', algorithms: %w[zstd gzip brotli deflate], mime_types: %w[all], compress_streams: true
46
+ log_requests before: { level: "INFO", format: "[{request_id}] {method} {path_and_query} - {addr} " }, after: { level: "INFO", format: "[{request_id}] └─ {status} in {response_time}" }
47
+ static_assets \
48
+ relative_path: true,
49
+ allowed_extensions: [],
50
+ root_dir: '.',
51
+ not_found_behavior: {error: 'not_found'},
52
+ auto_index: true,
53
+ try_html_extension: true,
54
+ max_file_size_in_memory: 1024 * 1024, # 1MB
55
+ max_files_in_memory: 1000,
56
+ file_check_interval: 1,
57
+ serve_hidden_files: false,
58
+ headers: {
59
+ 'X-Content-Type-Options' => 'nosniff'
60
+ }
61
+ end
62
+ end
63
+ elsif File.exist?(config_file_path.to_s)
64
+ DSL.evaluate(config_file_path)
65
+ elsif File.exist?("./config.ru")
66
+ DSL.evaluate do
67
+ preload true
68
+ rackup_file args.fetch(:rackup_file, "./config.ru")
69
+ end
70
+ else
71
+ DSL.evaluate{}
72
+ end
73
+
74
+ itsifile_config.transform_keys!(&:to_sym)
75
+
76
+ # We'll preload while we load config, if enabled.
77
+ middleware_loader = itsifile_config.fetch(:middleware_loader, -> {})
78
+ preload = args.fetch(:preload) { itsifile_config.fetch(:preload, false) }
79
+
80
+ case preload
81
+ # If we preload everything, then we'll load middleware and default rack app ahead of time
82
+ when true
83
+ preloaded_middleware = middleware_loader.call
84
+ middleware_loader = -> { preloaded_middleware }
85
+ # If we're just preloading a specific gem group, we'll do that here too
86
+ when Symbol
87
+ Bundler.require(preload)
88
+ end
89
+
90
+ {
91
+ workers: args.fetch(:workers) { itsifile_config.fetch(:workers, 1) },
92
+ worker_memory_limit: args.fetch(:worker_memory_limit) { itsifile_config.fetch(:worker_memory_limit, nil) },
93
+ silence: args.fetch(:silence) { itsifile_config.fetch(:silence, false) },
94
+ shutdown_timeout: args.fetch(:shutdown_timeout) { itsifile_config.fetch(:shutdown_timeout, 5) },
95
+ hooks: itsifile_config.fetch(:hooks, nil),
96
+ preload: !!preload,
97
+ request_timeout: itsifile_config.fetch(:request_timeout, nil),
98
+ notify_watchers: itsifile_config.fetch(:notify_watchers, nil),
99
+ threads: args.fetch(:threads) { itsifile_config.fetch(:threads, 1) },
100
+ scheduler_threads: args.fetch(:scheduler_threads) { itsifile_config.fetch(:scheduler_threads, nil) },
101
+ streamable_body: args.fetch(:streamable_body) { itsifile_config.fetch(:streamable_body, false) },
102
+ multithreaded_reactor: args.fetch(:multithreaded_reactor) do
103
+ itsifile_config.fetch(:multithreaded_reactor, nil)
104
+ end,
105
+ pin_worker_cores: args.fetch(:pin_worker_cores) { itsifile_config.fetch(:pin_worker_cores, true) },
106
+ scheduler_class: args.fetch(:scheduler_class) { itsifile_config.fetch(:scheduler_class, nil) },
107
+ oob_gc_responses_threshold: args.fetch(:oob_gc_responses_threshold) do
108
+ itsifile_config.fetch(:oob_gc_responses_threshold, nil)
109
+ end,
110
+ log_level: args.fetch(:log_level) { itsifile_config.fetch(:log_level, nil) },
111
+ log_format: args.fetch(:log_format) { itsifile_config.fetch(:log_format, nil) },
112
+ log_target: args.fetch(:log_target) { itsifile_config.fetch(:log_target, nil) },
113
+ binds: args.fetch(:binds) { itsifile_config.fetch(:binds, ["http://0.0.0.0:3000"]) },
114
+ middleware_loader: middleware_loader,
115
+ listeners: args.fetch(:listeners) { nil }
116
+ }.transform_keys(&:to_s)
117
+ end
118
+
119
+ # Reloads the entire process
120
+ # using exec, passing in any active file descriptors
121
+ # and previous invocation arguments
122
+ def self.reload_exec(listener_info)
123
+ if ENV["BUNDLE_BIN_PATH"]
124
+ exec "bundle", "exec", $PROGRAM_NAME, *@argv, "--listeners", listener_info
125
+ else
126
+ exec $PROGRAM_NAME, *@argv, "--listeners", listener_info
127
+ end
128
+ end
129
+
130
+ # Find config file path, if it exists.
131
+ def self.config_file_path(config_file_path = nil)
132
+ config_file_path ||= \
133
+ if File.exist?(ITSI_DEFAULT_CONFIG_FILE)
134
+ ITSI_DEFAULT_CONFIG_FILE
135
+ elsif File.exist?("config/#{ITSI_DEFAULT_CONFIG_FILE}")
136
+ "config/#{ITSI_DEFAULT_CONFIG_FILE}"
137
+ end
138
+ # Options simply pass through unless we've specified a config file
139
+ return unless File.exist?(config_file_path.to_s)
140
+
141
+ config_file_path
142
+ end
143
+
144
+ def self.pid_file_path
145
+ if Dir.exist?("tmp")
146
+ File.join("tmp", "itsi.pid")
147
+ else
148
+ ".itsi.pid"
149
+ end
150
+ end
151
+
152
+ # Write a default config file, if one doesn't exist.
153
+ def self.write_default
154
+ if File.exist?(ITSI_DEFAULT_CONFIG_FILE)
155
+ puts "#{ITSI_DEFAULT_CONFIG_FILE} already exists."
156
+ return
157
+ end
158
+
159
+ puts "Writing default configuration..."
160
+ File.open(ITSI_DEFAULT_CONFIG_FILE, "w") do |file|
161
+ file.write(IO.read("#{__dir__}/default_config/Itsi.rb"))
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,34 @@
1
+ # When you Run Itsi without a Rack app,
2
+ # we start a tiny little echo server, just so you can see it in action.
3
+ DEFAULT_INDEX = IO.read("#{__dir__}/index.html").freeze
4
+ DEFAULT_BINDS = ["http://0.0.0.0:3000"].freeze
5
+ DEFAULT_APP = lambda {
6
+ require "json"
7
+
8
+ Itsi::Server::RackInterface.for(lambda do |env|
9
+ headers, body = \
10
+ if env["itsi.response"].json?
11
+ [
12
+ { "Content-Type" => "application/json" },
13
+ [{ "message" => "You're running on Itsi!", "rack_env" => env,
14
+ "version" => Itsi::Server::VERSION }.to_json]
15
+ ]
16
+ else
17
+ [
18
+ { "Content-Type" => "text/html" },
19
+ [
20
+ format(
21
+ DEFAULT_INDEX,
22
+ REQUEST_METHOD: env["REQUEST_METHOD"],
23
+ PATH_INFO: env["PATH_INFO"],
24
+ SERVER_NAME: env["SERVER_NAME"],
25
+ SERVER_PORT: env["SERVER_PORT"],
26
+ REMOTE_ADDR: env["REMOTE_ADDR"],
27
+ HTTP_USER_AGENT: env["HTTP_USER_AGENT"]
28
+ )
29
+ ]
30
+ ]
31
+ end
32
+ [200, headers, body]
33
+ end)
34
+ }
@@ -0,0 +1,115 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Itsi - Default</title>
7
+ <style>
8
+ :root {
9
+ --bg-color: #f0f2f5;
10
+ --text-color: #333;
11
+ --link-color: #0052cc;
12
+ }
13
+ *,
14
+ *::before,
15
+ *::after {
16
+ box-sizing: border-box;
17
+ }
18
+ body {
19
+ margin: 0;
20
+ font-family: "Helvetica Neue", Arial, sans-serif;
21
+ background: var(--bg-color);
22
+ color: var(--text-color);
23
+ line-height: 1.6;
24
+ display: flex;
25
+ flex-direction: column;
26
+ align-items: center;
27
+ padding: 3rem 1rem;
28
+ }
29
+ header {
30
+ text-align: center;
31
+ margin-bottom: 2rem;
32
+ }
33
+ h1 {
34
+ font-size: 2.5rem;
35
+ margin-bottom: 0.5rem;
36
+ }
37
+ p {
38
+ font-size: 1.5rem;
39
+ margin-bottom: 2rem;
40
+ color: #555;
41
+ }
42
+ ul.fields {
43
+ list-style: none;
44
+ padding: 0;
45
+ margin: 0;
46
+ max-width: 100%%;
47
+ width: 100%%;
48
+ }
49
+ ul.fields li {
50
+ display: flex;
51
+ justify-content: space-between;
52
+ padding: 1rem;
53
+ border-bottom: 1px solid #ddd;
54
+ }
55
+ ul.fields li:last-child {
56
+ border-bottom: none;
57
+ }
58
+ .label {
59
+ font-weight: bold;
60
+ margin-right: 1rem;
61
+ }
62
+ /* Make it expansive: let content use more horizontal space on larger screens */
63
+ main {
64
+ max-width: 1200px;
65
+ width: 100%%;
66
+ }
67
+ /* Responsive adjustments for small devices */
68
+ @media (max-width: 480px) {
69
+ h1 {
70
+ font-size: 2.5rem;
71
+ }
72
+ p {
73
+ font-size: 1.2rem;
74
+ }
75
+ ul.fields li {
76
+ padding: 0.75rem;
77
+ }
78
+ }
79
+ </style>
80
+ </head>
81
+ <body>
82
+ <main>
83
+ <header>
84
+ <h1>You're running on Itsi!</h1>
85
+ <p>RACK environment:</p>
86
+ </header>
87
+ <ul class="fields">
88
+ <li>
89
+ <span class="label">REQUEST_METHOD:</span>
90
+ <span>%{REQUEST_METHOD}</span>
91
+ </li>
92
+ <li>
93
+ <span class="label">PATH_INFO:</span>
94
+ <span>%{PATH_INFO}</span>
95
+ </li>
96
+ <li>
97
+ <span class="label">SERVER_NAME:</span>
98
+ <span>%{SERVER_NAME}</span>
99
+ </li>
100
+ <li>
101
+ <span class="label">SERVER_PORT:</span>
102
+ <span>%{SERVER_PORT}</span>
103
+ </li>
104
+ <li>
105
+ <span class="label">REMOTE_ADDR:</span>
106
+ <span>%{REMOTE_ADDR}</span>
107
+ </li>
108
+ <li>
109
+ <span class="label">HTTP_USER_AGENT:</span>
110
+ <span>%{HTTP_USER_AGENT}</span>
111
+ </li>
112
+ </ul>
113
+ </main>
114
+ </body>
115
+ </html>
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is the default Itsi configuration file, installed when you run `itsi init`
4
+ # It contains a sane starting point for configuring your Itsi server.
5
+ # You can use this file in both development and production environments.
6
+ # Most of the options in this file can be overridden by command line options.
7
+ # Check out itsi -h to learn more about the command line options available to you.
8
+
9
+ env = ENV.fetch("APP_ENV") { ENV.fetch("RACK_ENV", "development") }
10
+
11
+ # Number of worker processes to spawn
12
+ # If more than 1, Itsi will be booted in Cluster mode
13
+ workers ENV.fetch("ITSI_WORKERS") {
14
+ require "etc"
15
+ env == "development" ? 1 : nil
16
+ }
17
+
18
+ # Number of threads to spawn per worker process
19
+ # For pure CPU bound applicationss, you'll get the best results keeping this number low
20
+ # Setting a value of 1 is great for superficial benchmarks, but in reality
21
+ # it's better to set this a bit higher to allow expensive requests to get overtaken and minimize head-of-line blocking
22
+ threads ENV.fetch("ITSI_THREADS", 3)
23
+
24
+ # If your application is IO bound (e.g. performing a lot of proxied HTTP requests, or heavy queries etc)
25
+ # you can see *substantial* benefits from enabling this option.
26
+ # To set this option, pass a string, not a class (as we will not have loaded the class yet)
27
+ # E.g.
28
+ # `fiber_scheduler "Itsi::Scheduler"` - The default fast and light-weight scheduler that comes with Itsi
29
+ # `fiber_scheduler "Async::Scheduler"` - Bring your own scheduler!
30
+ fiber_scheduler nil
31
+
32
+ # By default Itsi will run the Rack app from config.ru.
33
+ # You can provide an alternative Rack app file name here
34
+ # Or you can inline the app directly inside Itsi.rb.
35
+ # Only one of `run` and `rackup_file` can be used.
36
+ # E.g.
37
+ # require 'rack'
38
+ # run(Rack::Builder.app do
39
+ # use Rack::CommonLogger
40
+ # run ->(env) { [200, { 'content-type' => 'text/plain' }, ['OK']] }
41
+ # end)
42
+ rackup_file "config.ru"
43
+
44
+ # If you bind to https, without specifying a certificate, Itsi will use a self-signed certificate.
45
+ # The self-signed certificate will use a CA generated for your host and stored inside `ITSI_LOCAL_CA_DIR` (Defaults to ~/.itsi)
46
+ # bind "https://localhost:3000"
47
+ # bind "https://localhost:3000?domains=dev.itsi.fyi"
48
+ #
49
+ # If you want to use let's encrypt to generate you a real certificate you and pass cert=acme and an acme_email address to generate one.
50
+ # bind "https://itsi.fyi?cert=acme&acme_email=admin@itsi.fyi"
51
+ # You can generate certificates for multiple domains at once, by passing a comma-separated list of domains
52
+ # bind "https://0.0.0.0?domains=foo.itsi.fyi,bar.itsi.fyi&cert=acme&acme_email=admin@itsi.fyi"
53
+ #
54
+ # If you already have a certificate you can specify it using the cert and key parameters
55
+ # bind "https://itsi.fyi?cert=/path/to/cert.pem&key=/path/to/key.pem"
56
+ #
57
+ # You can also bind to a unix socket or a tls unix socket. E.g.
58
+ # bind "unix:///tmp/itsi.sock"
59
+ # bind "tls:///tmp/itsi.secure.sock"
60
+
61
+ if env == "development"
62
+ bind "http://localhost:3000"
63
+ else
64
+ bind "https://0.0.0.0?domains=#{ENV["PRODUCTION_DOMAINS"]}&cert=acme&acme_email=admin@itsi.fyi"
65
+ end
66
+
67
+ # If you want to preload the application, set preload to true
68
+ # to load the entire rack-app defined in rack_file_name before forking.
69
+ # Alternatively, you can preload just a specific set of gems in a group in your gemfile,
70
+ # by providing the group name here.
71
+ # E.g.
72
+ #
73
+ # preload :preload # Load gems inside the preload group
74
+ # preload false # Don't preload.
75
+ #
76
+ # If you want to be able to perform zero-downtime deploys using a single itsi process,
77
+ # you should disable preloads, so that the application is loaded fresh each time a new worker boots
78
+ preload true
79
+
80
+ # Set the maximum memory limit for each worker process in bytes
81
+ # When this limit is reached, the worker will be gracefully restarted.
82
+ # Only one worker is restarted at a time to ensure we don't take down
83
+ # all of them at once, if they reach the threshold simultaneously.
84
+ worker_memory_limit 1024 * 1024 * 1024
85
+
86
+ # You can provide an optional block of code to run, when a worker hits its memory threshold (Use this to send yourself an alert,
87
+ # write metrics to disk etc. etc.)
88
+ after_memory_threshold_reached do |pid|
89
+ puts "Worker #{pid} has reached its memory threshold and will restart"
90
+ end
91
+
92
+ # Do clean up of any non-threadsafe resources before forking a new worker here.
93
+ before_fork {}
94
+
95
+ # Reinitialize any non-threadsafe resources after forking a new worker here.
96
+ after_fork {}
97
+
98
+ # Shutdown timeout
99
+ # Number of seconds to wait for workers to gracefully shutdown before killing them.
100
+ shutdown_timeout 5
101
+
102
+ # Set this to false for application environments that require rack.input to be a rewindable body
103
+ # (like Rails). For rack applications that can stream inputs, you can set this to true for a more memory-efficient approach.
104
+ stream_body false
105
+
106
+ # OOB GC responses threshold
107
+ # Specifies how frequently OOB gc should be triggered during periods where there is a gap in queued requests.
108
+ # Setting this too low can substantially worsen performance
109
+ oob_gc_responses_threshold 512
110
+
111
+ # Log level
112
+ # Set this to one of the following values: debug, info, warn, error, fatal
113
+ # Can also be set using the ITSI_LOG environment variable
114
+ log_level :info
115
+
116
+ # Log Format
117
+ # Set this to be either :ansi or :json. If you leave it blank Itsi will try
118
+ # and auto-detect the format based on the TTY environment.
119
+ log_format :auto
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is the default Itsi configuration file, installed when you run `itsi init`
4
+ # It contains a sane starting point for configuring your Itsi server.
5
+ # You can use this file in both development and production environments.
6
+ # Most of the options in this file can be overridden by command line options.
7
+ # Check out itsi -h to learn more about the command line options available to you.
8
+
9
+ env = ENV.fetch("APP_ENV") { ENV.fetch("RACK_ENV", "development") }
10
+
11
+ # Number of worker processes to spawn
12
+ # If more than 1, Itsi will be booted in Cluster mode
13
+ workers ENV.fetch("ITSI_WORKERS") {
14
+ require "etc"
15
+ env == "development" ? 1 : nil
16
+ }
17
+
18
+ # Number of threads to spawn per worker process
19
+ # For pure CPU bound applicationss, you'll get the best results keeping this number low
20
+ # Setting a value of 1 is great for superficial benchmarks, but in reality
21
+ # it's better to set this a bit higher to allow expensive requests to get overtaken and minimize head-of-line blocking
22
+ threads ENV.fetch("ITSI_THREADS", 3)
23
+
24
+ # If your application is IO bound (e.g. performing a lot of proxied HTTP requests, or heavy queries etc)
25
+ # you can see *substantial* benefits from enabling this option.
26
+ # To set this option, pass a string, not a class (as we will not have loaded the class yet)
27
+ # E.g.
28
+ # `fiber_scheduler "Itsi::Scheduler"` - The default fast and light-weight scheduler that comes with Itsi
29
+ # `fiber_scheduler "Async::Scheduler"` - Bring your own scheduler!
30
+ fiber_scheduler nil
31
+
32
+ # If you bind to https, without specifying a certificate, Itsi will use a self-signed certificate.
33
+ # The self-signed certificate will use a CA generated for your host and stored inside `ITSI_LOCAL_CA_DIR` (Defaults to ~/.itsi)
34
+ # bind "https://localhost:3000"
35
+ # bind "https://localhost:3000?domains=dev.itsi.fyi"
36
+ #
37
+ # If you want to use let's encrypt to generate you a real certificate you and pass cert=acme and an acme_email address to generate one.
38
+ # bind "https://itsi.fyi?cert=acme&acme_email=admin@itsi.fyi"
39
+ # You can generate certificates for multiple domains at once, by passing a comma-separated list of domains
40
+ # bind "https://0.0.0.0?domains=foo.itsi.fyi,bar.itsi.fyi&cert=acme&acme_email=admin@itsi.fyi"
41
+ #
42
+ # If you already have a certificate you can specify it using the cert and key parameters
43
+ # bind "https://itsi.fyi?cert=/path/to/cert.pem&key=/path/to/key.pem"
44
+ #
45
+ # You can also bind to a unix socket or a tls unix socket. E.g.
46
+ # bind "unix:///tmp/itsi.sock"
47
+ # bind "tls:///tmp/itsi.secure.sock"
48
+
49
+ if env == "development"
50
+ bind "http://localhost:3000"
51
+ else
52
+ bind "https://0.0.0.0?domains=#{ENV["PRODUCTION_DOMAINS"]}&cert=acme&acme_email=admin@itsi.fyi"
53
+ end
54
+
55
+ # If you want to preload the application, set preload to true
56
+ # to load the entire rack-app defined in rack_file_name before forking.
57
+ # Alternatively, you can preload just a specific set of gems in a group in your gemfile,
58
+ # by providing the group name here.
59
+ # E.g.
60
+ #
61
+ # preload :preload # Load gems inside the preload group
62
+ # preload false # Don't preload.
63
+ #
64
+ # If you want to be able to perform zero-downtime deploys using a single itsi process,
65
+ # you should disable preloads, so that the application is loaded fresh each time a new worker boots
66
+ preload true
67
+
68
+ # Set the maximum memory limit for each worker process in bytes
69
+ # When this limit is reached, the worker will be gracefully restarted.
70
+ # Only one worker is restarted at a time to ensure we don't take down
71
+ # all of them at once, if they reach the threshold simultaneously.
72
+ worker_memory_limit 1024 * 1024 * 1024
73
+
74
+ # You can provide an optional block of code to run, when a worker hits its memory threshold (Use this to send yourself an alert,
75
+ # write metrics to disk etc. etc.)
76
+ after_memory_threshold_reached do |pid|
77
+ puts "Worker #{pid} has reached its memory threshold and will restart"
78
+ end
79
+
80
+ # Do clean up of any non-threadsafe resources before forking a new worker here.
81
+ before_fork {}
82
+
83
+ # Reinitialize any non-threadsafe resources after forking a new worker here.
84
+ after_fork {}
85
+
86
+ # Shutdown timeout
87
+ # Number of seconds to wait for workers to gracefully shutdown before killing them.
88
+ shutdown_timeout 5
89
+
90
+ # Set this to false for application environments that require rack.input to be a rewindable body
91
+ # (like Rails). For rack applications that can stream inputs, you can set this to true for a more memory-efficient approach.
92
+ stream_body false
93
+
94
+ # OOB GC responses threshold
95
+ # Specifies how frequently OOB gc should be triggered during periods where there is a gap in queued requests.
96
+ # Setting this too low can substantially worsen performance
97
+ oob_gc_responses_threshold 512
98
+
99
+ # Log level
100
+ # Set this to one of the following values: debug, info, warn, error, fatal
101
+ # Can also be set using the ITSI_LOG environment variable
102
+ log_level :info
103
+
104
+ # Log Format
105
+ # Set this to be either :ansi or :json. If you leave it blank Itsi will try
106
+ # and auto-detect the format based on the TTY environment.
107
+ log_format :auto