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.
Files changed (293) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +1535 -45
  3. data/{sandbox/itsi_itsi_file/Itsi.rb → Itsi.rb} +19 -13
  4. data/Rakefile +8 -7
  5. data/crates/itsi_error/src/lib.rs +9 -0
  6. data/crates/itsi_rb_helpers/Cargo.toml +1 -0
  7. data/crates/itsi_rb_helpers/src/heap_value.rs +18 -0
  8. data/crates/itsi_rb_helpers/src/lib.rs +34 -7
  9. data/crates/itsi_server/Cargo.toml +69 -30
  10. data/crates/itsi_server/src/lib.rs +79 -147
  11. data/crates/itsi_server/src/{body_proxy → ruby_types/itsi_body_proxy}/big_bytes.rs +10 -5
  12. data/crates/itsi_server/src/{body_proxy/itsi_body_proxy.rs → ruby_types/itsi_body_proxy/mod.rs} +22 -3
  13. data/crates/itsi_server/src/ruby_types/itsi_grpc_request.rs +147 -0
  14. data/crates/itsi_server/src/ruby_types/itsi_grpc_response.rs +19 -0
  15. data/crates/itsi_server/src/ruby_types/itsi_grpc_stream/mod.rs +216 -0
  16. data/{gems/server/ext/itsi_server/src/request/itsi_request.rs → crates/itsi_server/src/ruby_types/itsi_http_request.rs} +101 -117
  17. data/crates/itsi_server/src/{response/itsi_response.rs → ruby_types/itsi_http_response.rs} +72 -41
  18. data/crates/itsi_server/src/ruby_types/itsi_server/file_watcher.rs +225 -0
  19. data/crates/itsi_server/src/ruby_types/itsi_server/itsi_server_config.rs +355 -0
  20. data/crates/itsi_server/src/ruby_types/itsi_server.rs +82 -0
  21. data/crates/itsi_server/src/ruby_types/mod.rs +55 -0
  22. data/crates/itsi_server/src/server/bind.rs +13 -5
  23. data/crates/itsi_server/src/server/byte_frame.rs +32 -0
  24. data/crates/itsi_server/src/server/cache_store.rs +74 -0
  25. data/crates/itsi_server/src/server/itsi_service.rs +172 -0
  26. data/crates/itsi_server/src/server/lifecycle_event.rs +3 -0
  27. data/crates/itsi_server/src/server/listener.rs +102 -2
  28. data/crates/itsi_server/src/server/middleware_stack/middleware.rs +153 -0
  29. data/crates/itsi_server/src/server/middleware_stack/middlewares/allow_list.rs +47 -0
  30. data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_api_key.rs +58 -0
  31. data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_basic.rs +82 -0
  32. data/crates/itsi_server/src/server/middleware_stack/middlewares/auth_jwt.rs +321 -0
  33. data/crates/itsi_server/src/server/middleware_stack/middlewares/cache_control.rs +139 -0
  34. data/crates/itsi_server/src/server/middleware_stack/middlewares/compression.rs +300 -0
  35. data/crates/itsi_server/src/server/middleware_stack/middlewares/cors.rs +287 -0
  36. data/crates/itsi_server/src/server/middleware_stack/middlewares/deny_list.rs +48 -0
  37. data/crates/itsi_server/src/server/middleware_stack/middlewares/error_response.rs +127 -0
  38. data/crates/itsi_server/src/server/middleware_stack/middlewares/etag.rs +191 -0
  39. data/crates/itsi_server/src/server/middleware_stack/middlewares/grpc_service.rs +72 -0
  40. data/crates/itsi_server/src/server/middleware_stack/middlewares/header_interpretation.rs +85 -0
  41. data/crates/itsi_server/src/server/middleware_stack/middlewares/intrusion_protection.rs +195 -0
  42. data/crates/itsi_server/src/server/middleware_stack/middlewares/log_requests.rs +82 -0
  43. data/crates/itsi_server/src/server/middleware_stack/middlewares/mod.rs +82 -0
  44. data/crates/itsi_server/src/server/middleware_stack/middlewares/proxy.rs +216 -0
  45. data/crates/itsi_server/src/server/middleware_stack/middlewares/rate_limit.rs +124 -0
  46. data/crates/itsi_server/src/server/middleware_stack/middlewares/redirect.rs +76 -0
  47. data/crates/itsi_server/src/server/middleware_stack/middlewares/request_headers.rs +43 -0
  48. data/crates/itsi_server/src/server/middleware_stack/middlewares/response_headers.rs +34 -0
  49. data/crates/itsi_server/src/server/middleware_stack/middlewares/ruby_app.rs +93 -0
  50. data/crates/itsi_server/src/server/middleware_stack/middlewares/static_assets.rs +162 -0
  51. data/crates/itsi_server/src/server/middleware_stack/middlewares/string_rewrite.rs +158 -0
  52. data/crates/itsi_server/src/server/middleware_stack/middlewares/token_source.rs +12 -0
  53. data/crates/itsi_server/src/server/middleware_stack/mod.rs +315 -0
  54. data/crates/itsi_server/src/server/mod.rs +8 -1
  55. data/crates/itsi_server/src/server/process_worker.rs +38 -12
  56. data/crates/itsi_server/src/server/rate_limiter.rs +565 -0
  57. data/crates/itsi_server/src/server/request_job.rs +11 -0
  58. data/crates/itsi_server/src/server/serve_strategy/cluster_mode.rs +119 -42
  59. data/crates/itsi_server/src/server/serve_strategy/mod.rs +9 -6
  60. data/crates/itsi_server/src/server/serve_strategy/single_mode.rs +256 -111
  61. data/crates/itsi_server/src/server/signal.rs +19 -0
  62. data/crates/itsi_server/src/server/static_file_server.rs +984 -0
  63. data/crates/itsi_server/src/server/thread_worker.rs +139 -94
  64. data/crates/itsi_server/src/server/types.rs +43 -0
  65. data/crates/itsi_server/test.md +14 -0
  66. data/crates/itsi_tracing/Cargo.toml +1 -0
  67. data/crates/itsi_tracing/src/lib.rs +216 -45
  68. data/docs/.gitignore +7 -0
  69. data/docs/.gitpod.yml +15 -0
  70. data/docs/Itsi.rb +17 -0
  71. data/docs/content/_index.md +17 -0
  72. data/docs/content/about.md +6 -0
  73. data/docs/content/docs/_index.md +18 -0
  74. data/docs/content/docs/first-page.md +9 -0
  75. data/docs/content/docs/folder/_index.md +10 -0
  76. data/docs/content/docs/folder/leaf.md +7 -0
  77. data/docs/go.mod +5 -0
  78. data/docs/go.sum +2 -0
  79. data/docs/hugo.yaml +77 -0
  80. data/examples/static_assets_example.rb +83 -0
  81. data/gems/_index.md +18 -0
  82. data/gems/scheduler/CODE_OF_CONDUCT.md +7 -0
  83. data/gems/scheduler/Cargo.lock +75 -14
  84. data/gems/scheduler/README.md +5 -0
  85. data/gems/scheduler/_index.md +7 -0
  86. data/gems/scheduler/itsi-scheduler.gemspec +4 -1
  87. data/gems/scheduler/lib/itsi/scheduler/version.rb +1 -1
  88. data/gems/scheduler/lib/itsi/scheduler.rb +2 -2
  89. data/gems/scheduler/test/test_file_io.rb +0 -1
  90. data/gems/scheduler/test/test_itsi_scheduler.rb +1 -1
  91. data/gems/server/CHANGELOG.md +5 -0
  92. data/gems/server/CODE_OF_CONDUCT.md +7 -0
  93. data/gems/server/Cargo.lock +1536 -45
  94. data/gems/server/README.md +4 -0
  95. data/gems/server/_index.md +6 -0
  96. data/gems/server/exe/itsi +33 -74
  97. data/gems/server/itsi-server.gemspec +3 -2
  98. data/gems/server/lib/itsi/{request.rb → http_request.rb} +29 -5
  99. data/gems/server/lib/itsi/http_response.rb +39 -0
  100. data/gems/server/lib/itsi/server/Itsi.rb +11 -19
  101. data/gems/server/lib/itsi/server/config/dsl.rb +506 -0
  102. data/gems/server/lib/itsi/server/config.rb +103 -8
  103. data/gems/server/lib/itsi/server/default_app/default_app.rb +38 -0
  104. data/gems/server/lib/itsi/server/grpc_interface.rb +213 -0
  105. data/gems/server/lib/itsi/server/rack/handler/itsi.rb +8 -17
  106. data/gems/server/lib/itsi/server/rack_interface.rb +23 -4
  107. data/gems/server/lib/itsi/server/scheduler_interface.rb +1 -1
  108. data/gems/server/lib/itsi/server/scheduler_mode.rb +4 -0
  109. data/gems/server/lib/itsi/server/signal_trap.rb +7 -1
  110. data/gems/server/lib/itsi/server/version.rb +1 -1
  111. data/gems/server/lib/itsi/server.rb +74 -63
  112. data/gems/server/lib/itsi/standard_headers.rb +86 -0
  113. data/gems/server/test/helpers/test_helper.rb +12 -12
  114. data/gems/server/test/test_itsi_server.rb +2 -2
  115. data/lib/itsi/version.rb +1 -1
  116. data/sandbox/itsi_file/Gemfile +11 -0
  117. data/sandbox/itsi_file/Gemfile.lock +69 -0
  118. data/sandbox/itsi_file/Itsi.rb +276 -0
  119. data/sandbox/itsi_file/error.html +2 -0
  120. data/sandbox/itsi_file/organisations_controller.rb +20 -0
  121. data/sandbox/itsi_file/public/assets/image.png +0 -0
  122. data/sandbox/itsi_file/public/assets/index.html +1 -0
  123. data/sandbox/itsi_sandbox_hanami/Gemfile.lock +2 -2
  124. data/sandbox/itsi_sandbox_rack/Gemfile.lock +2 -2
  125. data/sandbox/itsi_sandbox_rack/config.ru +2 -15
  126. data/sandbox/itsi_sandbox_rails/.dockerignore +2 -5
  127. data/sandbox/itsi_sandbox_rails/.github/workflows/ci.yml +1 -1
  128. data/sandbox/itsi_sandbox_rails/.gitignore +2 -1
  129. data/sandbox/itsi_sandbox_rails/Dockerfile +6 -9
  130. data/sandbox/itsi_sandbox_rails/Gemfile +16 -22
  131. data/sandbox/itsi_sandbox_rails/Gemfile.lock +100 -225
  132. data/sandbox/itsi_sandbox_rails/app/assets/config/manifest.js +4 -0
  133. data/sandbox/itsi_sandbox_rails/app/assets/stylesheets/application.css +11 -6
  134. data/sandbox/itsi_sandbox_rails/app/channels/application_cable/channel.rb +4 -0
  135. data/sandbox/itsi_sandbox_rails/app/channels/application_cable/connection.rb +4 -0
  136. data/sandbox/itsi_sandbox_rails/app/controllers/live_controller.rb +7 -8
  137. data/sandbox/itsi_sandbox_rails/app/controllers/uploads_controller.rb +0 -3
  138. data/sandbox/itsi_sandbox_rails/app/views/layouts/application.html.erb +2 -7
  139. data/sandbox/itsi_sandbox_rails/bin/docker-entrypoint +3 -4
  140. data/sandbox/itsi_sandbox_rails/bin/setup +8 -5
  141. data/sandbox/itsi_sandbox_rails/config/application.rb +1 -35
  142. data/sandbox/itsi_sandbox_rails/config/cable.yml +3 -10
  143. data/sandbox/itsi_sandbox_rails/config/credentials.yml.enc +1 -1
  144. data/sandbox/itsi_sandbox_rails/config/database.yml +9 -19
  145. data/sandbox/itsi_sandbox_rails/config/environment.rb +1 -1
  146. data/sandbox/itsi_sandbox_rails/config/environments/development.rb +21 -12
  147. data/sandbox/itsi_sandbox_rails/config/environments/production.rb +49 -34
  148. data/sandbox/itsi_sandbox_rails/config/environments/test.rb +19 -5
  149. data/sandbox/itsi_sandbox_rails/config/initializers/assets.rb +5 -0
  150. data/sandbox/itsi_sandbox_rails/config/initializers/filter_parameter_logging.rb +1 -1
  151. data/sandbox/itsi_sandbox_rails/config/initializers/permissions_policy.rb +13 -0
  152. data/sandbox/itsi_sandbox_rails/config/puma.rb +2 -9
  153. data/sandbox/itsi_sandbox_rails/config.ru +0 -1
  154. data/sandbox/itsi_sandbox_rails/db/migrate/20250301041554_create_posts.rb +1 -1
  155. data/sandbox/itsi_sandbox_rails/db/schema.rb +2 -2
  156. data/sandbox/itsi_sandbox_rails/lib/assets/.keep +0 -0
  157. data/sandbox/itsi_sandbox_rails/public/404.html +66 -113
  158. data/sandbox/itsi_sandbox_rails/public/406-unsupported-browser.html +65 -113
  159. data/sandbox/itsi_sandbox_rails/public/422.html +66 -113
  160. data/sandbox/itsi_sandbox_rails/public/500.html +65 -113
  161. data/sandbox/itsi_sandbox_rails/public/icon.png +0 -0
  162. data/sandbox/itsi_sandbox_rails/public/icon.svg +2 -2
  163. data/sandbox/itsi_sandbox_rails/test/channels/application_cable/connection_test.rb +13 -0
  164. data/sandbox/itsi_sandbox_roda/Gemfile.lock +3 -10
  165. data/tasks.txt +72 -35
  166. metadata +89 -139
  167. data/crates/itsi_server/src/body_proxy/mod.rs +0 -2
  168. data/crates/itsi_server/src/request/itsi_request.rs +0 -298
  169. data/crates/itsi_server/src/request/mod.rs +0 -1
  170. data/crates/itsi_server/src/response/mod.rs +0 -1
  171. data/crates/itsi_server/src/server/itsi_server.rs +0 -288
  172. data/gems/scheduler/ext/itsi_error/Cargo.lock +0 -368
  173. data/gems/scheduler/ext/itsi_error/Cargo.toml +0 -11
  174. data/gems/scheduler/ext/itsi_error/src/from.rs +0 -68
  175. data/gems/scheduler/ext/itsi_error/src/lib.rs +0 -24
  176. data/gems/scheduler/ext/itsi_instrument_entry/Cargo.toml +0 -15
  177. data/gems/scheduler/ext/itsi_instrument_entry/src/lib.rs +0 -31
  178. data/gems/scheduler/ext/itsi_rb_helpers/Cargo.lock +0 -355
  179. data/gems/scheduler/ext/itsi_rb_helpers/Cargo.toml +0 -10
  180. data/gems/scheduler/ext/itsi_rb_helpers/src/heap_value.rs +0 -121
  181. data/gems/scheduler/ext/itsi_rb_helpers/src/lib.rs +0 -201
  182. data/gems/scheduler/ext/itsi_scheduler/Cargo.toml +0 -24
  183. data/gems/scheduler/ext/itsi_scheduler/extconf.rb +0 -6
  184. data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler/io_helpers.rs +0 -56
  185. data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler/io_waiter.rs +0 -44
  186. data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler/timer.rs +0 -44
  187. data/gems/scheduler/ext/itsi_scheduler/src/itsi_scheduler.rs +0 -308
  188. data/gems/scheduler/ext/itsi_scheduler/src/lib.rs +0 -38
  189. data/gems/scheduler/ext/itsi_server/Cargo.lock +0 -2956
  190. data/gems/scheduler/ext/itsi_server/Cargo.toml +0 -50
  191. data/gems/scheduler/ext/itsi_server/extconf.rb +0 -6
  192. data/gems/scheduler/ext/itsi_server/src/body_proxy/big_bytes.rs +0 -104
  193. data/gems/scheduler/ext/itsi_server/src/body_proxy/itsi_body_proxy.rs +0 -122
  194. data/gems/scheduler/ext/itsi_server/src/body_proxy/mod.rs +0 -2
  195. data/gems/scheduler/ext/itsi_server/src/env.rs +0 -43
  196. data/gems/scheduler/ext/itsi_server/src/lib.rs +0 -180
  197. data/gems/scheduler/ext/itsi_server/src/request/itsi_request.rs +0 -298
  198. data/gems/scheduler/ext/itsi_server/src/request/mod.rs +0 -1
  199. data/gems/scheduler/ext/itsi_server/src/response/itsi_response.rs +0 -357
  200. data/gems/scheduler/ext/itsi_server/src/response/mod.rs +0 -1
  201. data/gems/scheduler/ext/itsi_server/src/server/bind.rs +0 -174
  202. data/gems/scheduler/ext/itsi_server/src/server/bind_protocol.rs +0 -37
  203. data/gems/scheduler/ext/itsi_server/src/server/io_stream.rs +0 -104
  204. data/gems/scheduler/ext/itsi_server/src/server/itsi_server.rs +0 -288
  205. data/gems/scheduler/ext/itsi_server/src/server/lifecycle_event.rs +0 -9
  206. data/gems/scheduler/ext/itsi_server/src/server/listener.rs +0 -318
  207. data/gems/scheduler/ext/itsi_server/src/server/mod.rs +0 -11
  208. data/gems/scheduler/ext/itsi_server/src/server/process_worker.rs +0 -203
  209. data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +0 -260
  210. data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/mod.rs +0 -27
  211. data/gems/scheduler/ext/itsi_server/src/server/serve_strategy/single_mode.rs +0 -276
  212. data/gems/scheduler/ext/itsi_server/src/server/signal.rs +0 -74
  213. data/gems/scheduler/ext/itsi_server/src/server/thread_worker.rs +0 -399
  214. data/gems/scheduler/ext/itsi_server/src/server/tls/locked_dir_cache.rs +0 -132
  215. data/gems/scheduler/ext/itsi_server/src/server/tls.rs +0 -265
  216. data/gems/scheduler/ext/itsi_tracing/Cargo.lock +0 -274
  217. data/gems/scheduler/ext/itsi_tracing/Cargo.toml +0 -16
  218. data/gems/scheduler/ext/itsi_tracing/src/lib.rs +0 -58
  219. data/gems/server/ext/itsi_error/Cargo.lock +0 -368
  220. data/gems/server/ext/itsi_error/Cargo.toml +0 -11
  221. data/gems/server/ext/itsi_error/src/from.rs +0 -68
  222. data/gems/server/ext/itsi_error/src/lib.rs +0 -24
  223. data/gems/server/ext/itsi_instrument_entry/Cargo.toml +0 -15
  224. data/gems/server/ext/itsi_instrument_entry/src/lib.rs +0 -31
  225. data/gems/server/ext/itsi_rb_helpers/Cargo.lock +0 -355
  226. data/gems/server/ext/itsi_rb_helpers/Cargo.toml +0 -10
  227. data/gems/server/ext/itsi_rb_helpers/src/heap_value.rs +0 -121
  228. data/gems/server/ext/itsi_rb_helpers/src/lib.rs +0 -201
  229. data/gems/server/ext/itsi_scheduler/Cargo.toml +0 -24
  230. data/gems/server/ext/itsi_scheduler/extconf.rb +0 -6
  231. data/gems/server/ext/itsi_scheduler/src/itsi_scheduler/io_helpers.rs +0 -56
  232. data/gems/server/ext/itsi_scheduler/src/itsi_scheduler/io_waiter.rs +0 -44
  233. data/gems/server/ext/itsi_scheduler/src/itsi_scheduler/timer.rs +0 -44
  234. data/gems/server/ext/itsi_scheduler/src/itsi_scheduler.rs +0 -308
  235. data/gems/server/ext/itsi_scheduler/src/lib.rs +0 -38
  236. data/gems/server/ext/itsi_server/Cargo.lock +0 -2956
  237. data/gems/server/ext/itsi_server/Cargo.toml +0 -50
  238. data/gems/server/ext/itsi_server/extconf.rb +0 -6
  239. data/gems/server/ext/itsi_server/src/body_proxy/big_bytes.rs +0 -104
  240. data/gems/server/ext/itsi_server/src/body_proxy/itsi_body_proxy.rs +0 -122
  241. data/gems/server/ext/itsi_server/src/body_proxy/mod.rs +0 -2
  242. data/gems/server/ext/itsi_server/src/env.rs +0 -43
  243. data/gems/server/ext/itsi_server/src/lib.rs +0 -180
  244. data/gems/server/ext/itsi_server/src/request/mod.rs +0 -1
  245. data/gems/server/ext/itsi_server/src/response/itsi_response.rs +0 -357
  246. data/gems/server/ext/itsi_server/src/response/mod.rs +0 -1
  247. data/gems/server/ext/itsi_server/src/server/bind.rs +0 -174
  248. data/gems/server/ext/itsi_server/src/server/bind_protocol.rs +0 -37
  249. data/gems/server/ext/itsi_server/src/server/io_stream.rs +0 -104
  250. data/gems/server/ext/itsi_server/src/server/itsi_server.rs +0 -288
  251. data/gems/server/ext/itsi_server/src/server/lifecycle_event.rs +0 -9
  252. data/gems/server/ext/itsi_server/src/server/listener.rs +0 -318
  253. data/gems/server/ext/itsi_server/src/server/mod.rs +0 -11
  254. data/gems/server/ext/itsi_server/src/server/process_worker.rs +0 -203
  255. data/gems/server/ext/itsi_server/src/server/serve_strategy/cluster_mode.rs +0 -260
  256. data/gems/server/ext/itsi_server/src/server/serve_strategy/mod.rs +0 -27
  257. data/gems/server/ext/itsi_server/src/server/serve_strategy/single_mode.rs +0 -276
  258. data/gems/server/ext/itsi_server/src/server/signal.rs +0 -74
  259. data/gems/server/ext/itsi_server/src/server/thread_worker.rs +0 -399
  260. data/gems/server/ext/itsi_server/src/server/tls/locked_dir_cache.rs +0 -132
  261. data/gems/server/ext/itsi_server/src/server/tls.rs +0 -265
  262. data/gems/server/ext/itsi_tracing/Cargo.lock +0 -274
  263. data/gems/server/ext/itsi_tracing/Cargo.toml +0 -16
  264. data/gems/server/ext/itsi_tracing/src/lib.rs +0 -58
  265. data/gems/server/lib/itsi/server/options_dsl.rb +0 -401
  266. data/gems/server/lib/itsi/stream_io.rb +0 -38
  267. data/location_dsl.rb +0 -381
  268. data/sandbox/itsi_sandbox_rails/.kamal/hooks/docker-setup.sample +0 -3
  269. data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-app-boot.sample +0 -3
  270. data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-deploy.sample +0 -14
  271. data/sandbox/itsi_sandbox_rails/.kamal/hooks/post-proxy-reboot.sample +0 -3
  272. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-app-boot.sample +0 -3
  273. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-build.sample +0 -51
  274. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-connect.sample +0 -47
  275. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-deploy.sample +0 -109
  276. data/sandbox/itsi_sandbox_rails/.kamal/hooks/pre-proxy-reboot.sample +0 -3
  277. data/sandbox/itsi_sandbox_rails/.kamal/secrets +0 -17
  278. data/sandbox/itsi_sandbox_rails/bin/dev +0 -2
  279. data/sandbox/itsi_sandbox_rails/bin/jobs +0 -6
  280. data/sandbox/itsi_sandbox_rails/bin/kamal +0 -27
  281. data/sandbox/itsi_sandbox_rails/bin/thrust +0 -5
  282. data/sandbox/itsi_sandbox_rails/config/cache.yml +0 -16
  283. data/sandbox/itsi_sandbox_rails/config/deploy.yml +0 -116
  284. data/sandbox/itsi_sandbox_rails/config/queue.yml +0 -18
  285. data/sandbox/itsi_sandbox_rails/config/recurring.yml +0 -10
  286. data/sandbox/itsi_sandbox_rails/db/cable_schema.rb +0 -11
  287. data/sandbox/itsi_sandbox_rails/db/cache_schema.rb +0 -14
  288. data/sandbox/itsi_sandbox_rails/db/queue_schema.rb +0 -129
  289. data/sandbox/itsi_sandbox_rails/public/400.html +0 -114
  290. data/sandbox/itsi_sandbox_rails/test/fixtures/posts.yml +0 -9
  291. data/sandbox/itsi_sandbox_rails/test/models/post_test.rb +0 -7
  292. /data/{sandbox/itsi_sandbox_rails/script/.keep → crates/_index.md} +0 -0
  293. /data/gems/server/lib/itsi/{index.html → server/default_app/index.html} +0 -0
@@ -1,357 +0,0 @@
1
- use bytes::{Bytes, BytesMut};
2
- use derive_more::Debug;
3
- use futures::stream::{unfold, StreamExt};
4
- use http::{
5
- header::TRANSFER_ENCODING, request::Parts, HeaderMap, HeaderName, HeaderValue, Request,
6
- Response, StatusCode,
7
- };
8
- use http_body_util::{combinators::BoxBody, Empty, Full, StreamBody};
9
- use hyper::{body::Frame, upgrade::Upgraded};
10
- use hyper_util::rt::TokioIo;
11
- use itsi_error::Result;
12
- use itsi_tracing::error;
13
- use magnus::error::Result as MagnusResult;
14
- use parking_lot::RwLock;
15
- use std::{
16
- convert::Infallible,
17
- io,
18
- os::{fd::FromRawFd, unix::net::UnixStream},
19
- str::FromStr,
20
- sync::Arc,
21
- };
22
- use tokio::{
23
- io::AsyncReadExt,
24
- net::UnixStream as TokioUnixStream,
25
- sync::{
26
- mpsc::{self},
27
- watch,
28
- },
29
- };
30
- use tokio_stream::wrappers::ReceiverStream;
31
- use tokio_util::io::ReaderStream;
32
- use tracing::warn;
33
-
34
- use crate::server::serve_strategy::single_mode::RunningPhase;
35
-
36
- #[magnus::wrap(class = "Itsi::Response", free_immediately, size)]
37
- #[derive(Debug, Clone)]
38
- pub struct ItsiResponse {
39
- pub data: Arc<ResponseData>,
40
- pub accept: String,
41
- }
42
-
43
- #[derive(Debug)]
44
- pub struct ResponseData {
45
- pub response: RwLock<Option<Response<BoxBody<Bytes, Infallible>>>>,
46
- pub response_writer: RwLock<Option<mpsc::Sender<Option<Bytes>>>>,
47
- pub response_buffer: RwLock<BytesMut>,
48
- pub hijacked_socket: RwLock<Option<UnixStream>>,
49
- pub parts: Parts,
50
- }
51
-
52
- impl ItsiResponse {
53
- pub async fn build(
54
- &self,
55
- first_frame: Option<Bytes>,
56
- receiver: mpsc::Receiver<Option<Bytes>>,
57
- shutdown_rx: watch::Receiver<RunningPhase>,
58
- ) -> Response<BoxBody<Bytes, Infallible>> {
59
- if self.is_hijacked() {
60
- return match self.process_hijacked_response().await {
61
- Ok(result) => result,
62
- Err(e) => {
63
- error!("Error processing hijacked response: {}", e);
64
- Response::new(BoxBody::new(Empty::new()))
65
- }
66
- };
67
- }
68
-
69
- let mut response = self.data.response.write().take().unwrap();
70
- *response.body_mut() = if first_frame.is_none() {
71
- BoxBody::new(Empty::new())
72
- } else if receiver.is_closed() && receiver.is_empty() {
73
- BoxBody::new(Full::new(first_frame.unwrap()))
74
- } else {
75
- let initial_frame = tokio_stream::once(Ok(Frame::data(first_frame.unwrap())));
76
- let frame_stream = unfold(
77
- (ReceiverStream::new(receiver), shutdown_rx),
78
- |(mut receiver, mut shutdown_rx)| async move {
79
- if let RunningPhase::ShutdownPending = *shutdown_rx.borrow() {
80
- return None;
81
- }
82
- loop {
83
- tokio::select! {
84
- maybe_bytes = receiver.next() => {
85
- if let Some(bytes) = maybe_bytes {
86
- // We assume `bytes` is Some(Bytes) here.
87
- return Some((Ok(Frame::data(bytes.unwrap())), (receiver, shutdown_rx)));
88
- } else {
89
- // Receiver closed, end the stream.
90
- return None;
91
- }
92
- },
93
- _ = shutdown_rx.changed() => {
94
- match *shutdown_rx.borrow() {
95
- RunningPhase::ShutdownPending => {
96
- warn!("Disconnecting streaming client.");
97
- return None;
98
- },
99
- _ => continue,
100
- }
101
- }
102
- }
103
- }
104
- },
105
- );
106
-
107
- let combined_stream = initial_frame.chain(frame_stream);
108
- BoxBody::new(StreamBody::new(combined_stream))
109
- };
110
- response
111
- }
112
-
113
- pub fn close(&self) {
114
- self.data.response_writer.write().take();
115
- }
116
-
117
- async fn two_way_bridge(upgraded: Upgraded, local: TokioUnixStream) -> io::Result<()> {
118
- let client_io = TokioIo::new(upgraded);
119
-
120
- // Split each side
121
- let (mut lr, mut lw) = tokio::io::split(local);
122
- let (mut cr, mut cw) = tokio::io::split(client_io);
123
-
124
- let to_ruby = tokio::spawn(async move {
125
- if let Err(e) = tokio::io::copy(&mut cr, &mut lw).await {
126
- eprintln!("Error copying upgraded->local: {:?}", e);
127
- }
128
- });
129
- let from_ruby = tokio::spawn(async move {
130
- if let Err(e) = tokio::io::copy(&mut lr, &mut cw).await {
131
- eprintln!("Error copying upgraded->local: {:?}", e);
132
- }
133
- });
134
-
135
- let _ = to_ruby.await;
136
- let _ = from_ruby.await;
137
- Ok(())
138
- }
139
-
140
- async fn read_response_headers(&self, reader: &mut TokioUnixStream) -> Result<Vec<u8>> {
141
- let mut buf = [0u8; 1];
142
- let mut collected = Vec::new();
143
- loop {
144
- let n = reader.read(&mut buf).await?;
145
- if n == 0 {
146
- // EOF reached unexpectedly
147
- break;
148
- }
149
- collected.push(buf[0]);
150
- if collected.ends_with(b"\r\n\r\n") {
151
- break;
152
- }
153
- }
154
-
155
- Ok(collected)
156
- }
157
-
158
- pub async fn read_hijacked_headers(
159
- &self,
160
- ) -> Result<(HeaderMap, StatusCode, bool, TokioUnixStream)> {
161
- let hijacked_socket =
162
- self.data
163
- .hijacked_socket
164
- .write()
165
- .take()
166
- .ok_or(itsi_error::ItsiError::InvalidInput(
167
- "Couldn't hijack stream".to_owned(),
168
- ))?;
169
- let mut reader = TokioUnixStream::from_std(hijacked_socket).unwrap();
170
- let response_headers = self.read_response_headers(&mut reader).await?;
171
- let mut headers = [httparse::EMPTY_HEADER; 64];
172
- let mut resp = httparse::Response::new(&mut headers);
173
- resp.parse(&response_headers)?;
174
-
175
- let status = StatusCode::from_u16(resp.code.unwrap_or(200)).unwrap_or(StatusCode::OK);
176
- let mut headers = HeaderMap::new();
177
- for header in resp.headers.iter() {
178
- headers.insert(
179
- HeaderName::from_str(header.name).unwrap(),
180
- HeaderValue::from_bytes(header.value).unwrap(),
181
- );
182
- }
183
- let requires_upgrade = status == StatusCode::SWITCHING_PROTOCOLS;
184
- Ok((headers, status, requires_upgrade, reader))
185
- }
186
-
187
- pub async fn process_hijacked_response(&self) -> Result<Response<BoxBody<Bytes, Infallible>>> {
188
- let (headers, status, requires_upgrade, reader) = self.read_hijacked_headers().await?;
189
- let mut response = if requires_upgrade {
190
- let parts = self.data.parts.clone();
191
- tokio::spawn(async move {
192
- let mut req = Request::from_parts(parts, Empty::<Bytes>::new());
193
- match hyper::upgrade::on(&mut req).await {
194
- Ok(upgraded) => {
195
- Self::two_way_bridge(upgraded, reader)
196
- .await
197
- .expect("Error in creating two way bridge");
198
- }
199
- Err(e) => eprintln!("upgrade error: {:?}", e),
200
- }
201
- });
202
- Response::new(BoxBody::new(Empty::new()))
203
- } else {
204
- let stream = ReaderStream::new(reader);
205
- let boxed_body = if headers
206
- .get(TRANSFER_ENCODING)
207
- .is_some_and(|h| h == "chunked")
208
- {
209
- BoxBody::new(StreamBody::new(unfold(
210
- (stream, Vec::new()),
211
- |(mut stream, mut buf)| async move {
212
- loop {
213
- if let Some(pos) = buf.iter().position(|&b| b == b'\n') {
214
- let line = buf.drain(..=pos).collect::<Vec<u8>>();
215
- let line = std::str::from_utf8(&line).ok()?.trim();
216
- let chunk_size = usize::from_str_radix(line, 16).ok()?;
217
- if chunk_size == 0 {
218
- return None;
219
- }
220
- while buf.len() < chunk_size {
221
- match stream.next().await {
222
- Some(Ok(chunk)) => buf.extend_from_slice(&chunk),
223
- _ => return None,
224
- }
225
- }
226
- let data = buf.drain(..chunk_size).collect::<Vec<u8>>();
227
- if buf.starts_with(b"\r\n") {
228
- buf.drain(..2);
229
- }
230
- return Some((Ok(Frame::data(Bytes::from(data))), (stream, buf)));
231
- }
232
- match stream.next().await {
233
- Some(Ok(chunk)) => buf.extend_from_slice(&chunk),
234
- _ => return None,
235
- }
236
- }
237
- },
238
- )))
239
- } else {
240
- BoxBody::new(StreamBody::new(stream.map(
241
- |result: std::result::Result<Bytes, io::Error>| {
242
- result
243
- .map(Frame::data)
244
- .map_err(|e| unreachable!("unexpected io error: {:?}", e))
245
- },
246
- )))
247
- };
248
- Response::new(boxed_body)
249
- };
250
-
251
- *response.status_mut() = status;
252
- *response.headers_mut() = headers;
253
- Ok(response)
254
- }
255
-
256
- pub fn internal_server_error(&self, message: String) {
257
- error!(message);
258
- self.data.response_writer.write().take();
259
- if let Some(ref mut response) = *self.data.response.write() {
260
- *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
261
- }
262
- }
263
-
264
- pub fn send_frame(&self, frame: Bytes) -> MagnusResult<usize> {
265
- self.send_frame_into(frame, &self.data.response_writer)
266
- }
267
-
268
- pub fn send_and_close(&self, frame: Bytes) -> MagnusResult<usize> {
269
- let result = self.send_frame_into(frame, &self.data.response_writer);
270
- self.data.response_writer.write().take();
271
- result
272
- }
273
-
274
- pub fn send_frame_into(
275
- &self,
276
- frame: Bytes,
277
- writer: &RwLock<Option<mpsc::Sender<Option<Bytes>>>>,
278
- ) -> MagnusResult<usize> {
279
- if let Some(writer) = writer.write().as_ref() {
280
- writer
281
- .blocking_send(Some(frame))
282
- .map_err(|_| itsi_error::ItsiError::ClientConnectionClosed)
283
- .ok();
284
- }
285
- Ok(0)
286
- }
287
-
288
- pub fn is_hijacked(&self) -> bool {
289
- self.data.hijacked_socket.read().is_some()
290
- }
291
-
292
- pub fn close_write(&self) -> MagnusResult<bool> {
293
- self.data.response_writer.write().take();
294
- Ok(true)
295
- }
296
-
297
- pub fn is_html(&self) -> bool {
298
- self.accept.starts_with("text/html")
299
- }
300
-
301
- pub fn is_json(&self) -> bool {
302
- self.accept.starts_with("application/json")
303
- }
304
-
305
- pub fn close_read(&self) -> MagnusResult<bool> {
306
- Ok(true)
307
- }
308
-
309
- pub fn new(parts: Parts, response_writer: mpsc::Sender<Option<Bytes>>, accept: String) -> Self {
310
- Self {
311
- data: Arc::new(ResponseData {
312
- response: RwLock::new(Some(Response::new(BoxBody::new(Empty::new())))),
313
- response_writer: RwLock::new(Some(response_writer)),
314
- response_buffer: RwLock::new(BytesMut::new()),
315
- hijacked_socket: RwLock::new(None),
316
- parts,
317
- }),
318
- accept,
319
- }
320
- }
321
-
322
- pub fn add_header(&self, name: Bytes, value: Bytes) -> MagnusResult<()> {
323
- let header_name: HeaderName = HeaderName::from_bytes(&name).map_err(|e| {
324
- itsi_error::ItsiError::InvalidInput(format!("Invalid header name {:?}: {:?}", name, e))
325
- })?;
326
- let header_value = unsafe { HeaderValue::from_maybe_shared_unchecked(value) };
327
- if let Some(ref mut resp) = *self.data.response.write() {
328
- resp.headers_mut().insert(header_name, header_value);
329
- }
330
- Ok(())
331
- }
332
-
333
- pub fn set_status(&self, status: u16) -> MagnusResult<()> {
334
- if let Some(ref mut resp) = *self.data.response.write() {
335
- *resp.status_mut() = StatusCode::from_u16(status).map_err(|e| {
336
- itsi_error::ItsiError::InvalidInput(format!(
337
- "Invalid status code {:?}: {:?}",
338
- status, e
339
- ))
340
- })?;
341
- }
342
- Ok(())
343
- }
344
-
345
- pub fn hijack(&self, fd: i32) -> MagnusResult<()> {
346
- let stream = unsafe { UnixStream::from_raw_fd(fd) };
347
-
348
- *self.data.hijacked_socket.write() = Some(stream);
349
- if let Some(writer) = self.data.response_writer.write().as_ref() {
350
- writer
351
- .blocking_send(None)
352
- .map_err(|_| itsi_error::ItsiError::ClientConnectionClosed)?;
353
- }
354
- self.close();
355
- Ok(())
356
- }
357
- }
@@ -1 +0,0 @@
1
- pub mod itsi_response;
@@ -1,174 +0,0 @@
1
- use super::{
2
- bind_protocol::BindProtocol,
3
- tls::{configure_tls, ItsiTlsAcceptor},
4
- };
5
- use itsi_error::ItsiError;
6
- use std::{
7
- collections::HashMap,
8
- net::{IpAddr, Ipv4Addr, Ipv6Addr, ToSocketAddrs},
9
- path::PathBuf,
10
- str::FromStr,
11
- };
12
-
13
- #[derive(Debug, Clone)]
14
- pub enum BindAddress {
15
- Ip(IpAddr),
16
- UnixSocket(PathBuf),
17
- }
18
-
19
- impl Default for BindAddress {
20
- fn default() -> Self {
21
- BindAddress::Ip(IpAddr::V4(Ipv4Addr::UNSPECIFIED))
22
- }
23
- }
24
-
25
- #[derive(Default, Clone)]
26
- #[magnus::wrap(class = "Itsi::Bind")]
27
- pub struct Bind {
28
- pub address: BindAddress,
29
- pub port: Option<u16>, // None for Unix Sockets
30
- pub protocol: BindProtocol,
31
- pub tls_config: Option<ItsiTlsAcceptor>,
32
- }
33
-
34
- impl std::fmt::Debug for Bind {
35
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36
- match &self.address {
37
- BindAddress::Ip(ip) => match self.protocol {
38
- BindProtocol::Unix | BindProtocol::Unixs => {
39
- write!(f, "{}://{}", self.protocol, ip)
40
- }
41
- BindProtocol::Https if self.port == Some(443) => {
42
- write!(f, "{}://{}", self.protocol, ip)
43
- }
44
- BindProtocol::Http if self.port == Some(80) => {
45
- write!(f, "{}://{}", self.protocol, ip)
46
- }
47
- _ => match self.port {
48
- Some(port) => write!(f, "{}://{}:{}", self.protocol, ip, port),
49
- None => write!(f, "{}://{}", self.protocol, ip),
50
- },
51
- },
52
- BindAddress::UnixSocket(path) => {
53
- write!(f, "{}://{}", self.protocol, path.display())
54
- }
55
- }
56
- }
57
- }
58
-
59
- /// We can build a Bind from a string in the format `protocol://host:port?options`
60
- /// E.g.
61
- /// *`https://example.com:443?tls_cert=/path/to/cert.pem&tls_key=/path/to/key.pem`
62
- /// *`unix:///path/to/socket.sock`
63
- /// *`http://example.com:80`
64
- /// *`https://[::]:80`
65
- impl FromStr for Bind {
66
- type Err = ItsiError;
67
-
68
- fn from_str(s: &str) -> Result<Self, Self::Err> {
69
- let (protocol, remainder) = if let Some((proto, rest)) = s.split_once("://") {
70
- (proto.parse::<BindProtocol>()?, rest)
71
- } else {
72
- (BindProtocol::Https, s)
73
- };
74
-
75
- let (url, options) = if let Some((base, options)) = remainder.split_once('?') {
76
- (base, parse_bind_options(options))
77
- } else {
78
- (remainder, HashMap::new())
79
- };
80
-
81
- let (host, port) = if url.starts_with('[') {
82
- // IPv6 with brackets `[::]:port`
83
- if let Some(end) = url.find(']') {
84
- let host = &url[1..end]; // Extract `::`
85
- let port = url[end + 1..]
86
- .strip_prefix(':')
87
- .and_then(|p| p.parse().ok());
88
- (host, port)
89
- } else {
90
- return Err(ItsiError::InvalidInput(
91
- "Invalid IPv6 address format".to_owned(),
92
- ));
93
- }
94
- } else if let Some((h, p)) = url.rsplit_once(':') {
95
- // Check if `h` is an IPv6 address before assuming it's a port
96
- if h.contains('.') || h.parse::<Ipv4Addr>().is_ok() {
97
- (h, p.parse::<u16>().ok()) // IPv4 case
98
- } else if h.parse::<Ipv6Addr>().is_ok() {
99
- // If it's IPv6, require brackets for port
100
- return Err(ItsiError::InvalidInput(
101
- "IPv6 addresses must use [ ] when specifying a port".to_owned(),
102
- ));
103
- } else {
104
- (h, p.parse::<u16>().ok()) // Treat as a hostname
105
- }
106
- } else {
107
- (url, None)
108
- };
109
-
110
- let address = if let Ok(ip) = host.parse::<IpAddr>() {
111
- BindAddress::Ip(ip)
112
- } else {
113
- match protocol {
114
- BindProtocol::Https | BindProtocol::Http => resolve_hostname(host)
115
- .map(BindAddress::Ip)
116
- .ok_or(ItsiError::ArgumentError(format!(
117
- "Failed to resolve hostname {}",
118
- host
119
- )))?,
120
- BindProtocol::Unix | BindProtocol::Unixs => BindAddress::UnixSocket(host.into()),
121
- }
122
- };
123
-
124
- let port = match protocol {
125
- BindProtocol::Http => port.or(Some(80)),
126
- BindProtocol::Https => port.or(Some(443)),
127
- BindProtocol::Unix => None,
128
- BindProtocol::Unixs => None,
129
- };
130
-
131
- let tls_config = match protocol {
132
- BindProtocol::Http => None,
133
- BindProtocol::Https => Some(configure_tls(host, &options)?),
134
- BindProtocol::Unix => None,
135
- BindProtocol::Unixs => Some(configure_tls(host, &options)?),
136
- };
137
- let bind = Self {
138
- address,
139
- port,
140
- protocol,
141
- tls_config,
142
- };
143
- Ok(bind)
144
- }
145
- }
146
-
147
- fn parse_bind_options(query: &str) -> HashMap<String, String> {
148
- query
149
- .split('&')
150
- .filter_map(|pair| pair.split_once('='))
151
- .map(|(k, v)| (k.to_owned(), v.to_owned()))
152
- .collect()
153
- }
154
-
155
- /// Attempts to resolve a hostname into an IP address.
156
- fn resolve_hostname(hostname: &str) -> Option<IpAddr> {
157
- (hostname, 0)
158
- .to_socket_addrs()
159
- .ok()?
160
- .find_map(|addr| {
161
- if addr.is_ipv6() {
162
- Some(addr.ip()) // Prefer IPv6
163
- } else {
164
- None
165
- }
166
- })
167
- .or_else(|| {
168
- (hostname, 0)
169
- .to_socket_addrs()
170
- .ok()?
171
- .map(|addr| addr.ip())
172
- .next()
173
- }) // Fallback to IPv4
174
- }
@@ -1,37 +0,0 @@
1
- use itsi_error::ItsiError;
2
- use std::str::FromStr;
3
-
4
- #[derive(Debug, Default, Clone)]
5
- pub enum BindProtocol {
6
- #[default]
7
- Https,
8
- Http,
9
- Unix,
10
- Unixs,
11
- }
12
-
13
- impl FromStr for BindProtocol {
14
- type Err = ItsiError;
15
-
16
- fn from_str(s: &str) -> Result<Self, Self::Err> {
17
- match s {
18
- "http" => Ok(BindProtocol::Http),
19
- "https" => Ok(BindProtocol::Https),
20
- "unix" => Ok(BindProtocol::Unix),
21
- "tls" => Ok(BindProtocol::Unixs),
22
- _ => Err(ItsiError::UnsupportedProtocol(s.to_string())),
23
- }
24
- }
25
- }
26
-
27
- impl std::fmt::Display for BindProtocol {
28
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29
- let s = match self {
30
- BindProtocol::Https => "https",
31
- BindProtocol::Http => "http",
32
- BindProtocol::Unix => "unix",
33
- BindProtocol::Unixs => "tls",
34
- };
35
- write!(f, "{}", s)
36
- }
37
- }
@@ -1,104 +0,0 @@
1
- use super::listener::SockAddr;
2
- use pin_project::pin_project;
3
- use tokio::net::{TcpStream, UnixStream};
4
- use tokio_rustls::server::TlsStream;
5
-
6
- use std::os::unix::io::{AsRawFd, RawFd};
7
- use std::pin::Pin;
8
- use std::task::{Context, Poll};
9
- use tokio::io::{AsyncRead, AsyncWrite};
10
-
11
- #[pin_project(project = IoStreamEnumProj)]
12
- pub enum IoStream {
13
- Tcp {
14
- #[pin]
15
- stream: TcpStream,
16
- addr: SockAddr,
17
- },
18
- TcpTls {
19
- #[pin]
20
- stream: TlsStream<TcpStream>,
21
- addr: SockAddr,
22
- },
23
- Unix {
24
- #[pin]
25
- stream: UnixStream,
26
- addr: SockAddr,
27
- },
28
- UnixTls {
29
- #[pin]
30
- stream: TlsStream<UnixStream>,
31
- addr: SockAddr,
32
- },
33
- }
34
-
35
- impl IoStream {
36
- pub fn addr(&self) -> SockAddr {
37
- match self {
38
- IoStream::Tcp { addr, .. } => addr.clone(),
39
- IoStream::TcpTls { addr, .. } => addr.clone(),
40
- IoStream::Unix { addr, .. } => addr.clone(),
41
- IoStream::UnixTls { addr, .. } => addr.clone(),
42
- }
43
- }
44
- }
45
-
46
- impl AsyncRead for IoStream {
47
- fn poll_read(
48
- self: Pin<&mut Self>,
49
- cx: &mut Context<'_>,
50
- buf: &mut tokio::io::ReadBuf<'_>,
51
- ) -> Poll<std::io::Result<()>> {
52
- match self.project() {
53
- IoStreamEnumProj::Tcp { stream, .. } => stream.poll_read(cx, buf),
54
- IoStreamEnumProj::TcpTls { stream, .. } => stream.poll_read(cx, buf),
55
- IoStreamEnumProj::Unix { stream, .. } => stream.poll_read(cx, buf),
56
- IoStreamEnumProj::UnixTls { stream, .. } => stream.poll_read(cx, buf),
57
- }
58
- }
59
- }
60
-
61
- impl AsyncWrite for IoStream {
62
- fn poll_write(
63
- self: Pin<&mut Self>,
64
- cx: &mut Context<'_>,
65
- buf: &[u8],
66
- ) -> Poll<std::io::Result<usize>> {
67
- match self.project() {
68
- IoStreamEnumProj::Tcp { stream, .. } => stream.poll_write(cx, buf),
69
- IoStreamEnumProj::TcpTls { stream, .. } => stream.poll_write(cx, buf),
70
- IoStreamEnumProj::Unix { stream, .. } => stream.poll_write(cx, buf),
71
- IoStreamEnumProj::UnixTls { stream, .. } => stream.poll_write(cx, buf),
72
- }
73
- }
74
-
75
- fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
76
- match self.project() {
77
- IoStreamEnumProj::Tcp { stream, .. } => stream.poll_flush(cx),
78
- IoStreamEnumProj::TcpTls { stream, .. } => stream.poll_flush(cx),
79
- IoStreamEnumProj::Unix { stream, .. } => stream.poll_flush(cx),
80
- IoStreamEnumProj::UnixTls { stream, .. } => stream.poll_flush(cx),
81
- }
82
- }
83
-
84
- fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
85
- match self.project() {
86
- IoStreamEnumProj::Tcp { stream, .. } => stream.poll_shutdown(cx),
87
- IoStreamEnumProj::TcpTls { stream, .. } => stream.poll_shutdown(cx),
88
- IoStreamEnumProj::Unix { stream, .. } => stream.poll_shutdown(cx),
89
- IoStreamEnumProj::UnixTls { stream, .. } => stream.poll_shutdown(cx),
90
- }
91
- }
92
- }
93
-
94
- impl AsRawFd for IoStream {
95
- fn as_raw_fd(&self) -> RawFd {
96
- // For immutable access, we can simply pattern-match on self.
97
- match self {
98
- IoStream::Tcp { stream, .. } => stream.as_raw_fd(),
99
- IoStream::TcpTls { stream, .. } => stream.get_ref().0.as_raw_fd(),
100
- IoStream::Unix { stream, .. } => stream.as_raw_fd(),
101
- IoStream::UnixTls { stream, .. } => stream.get_ref().0.as_raw_fd(),
102
- }
103
- }
104
- }