hyperion-rb 1.6.2 → 2.11.0

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4768 -0
  3. data/README.md +222 -13
  4. data/ext/hyperion_h2_codec/Cargo.lock +7 -0
  5. data/ext/hyperion_h2_codec/Cargo.toml +33 -0
  6. data/ext/hyperion_h2_codec/extconf.rb +73 -0
  7. data/ext/hyperion_h2_codec/src/frames.rs +140 -0
  8. data/ext/hyperion_h2_codec/src/hpack/huffman.rs +161 -0
  9. data/ext/hyperion_h2_codec/src/hpack.rs +457 -0
  10. data/ext/hyperion_h2_codec/src/lib.rs +296 -0
  11. data/ext/hyperion_http/extconf.rb +28 -0
  12. data/ext/hyperion_http/h2_codec_glue.c +408 -0
  13. data/ext/hyperion_http/page_cache.c +1125 -0
  14. data/ext/hyperion_http/parser.c +473 -38
  15. data/ext/hyperion_http/sendfile.c +982 -0
  16. data/ext/hyperion_http/websocket.c +493 -0
  17. data/ext/hyperion_io_uring/Cargo.lock +33 -0
  18. data/ext/hyperion_io_uring/Cargo.toml +34 -0
  19. data/ext/hyperion_io_uring/extconf.rb +74 -0
  20. data/ext/hyperion_io_uring/src/lib.rs +316 -0
  21. data/lib/hyperion/adapter/rack.rb +370 -42
  22. data/lib/hyperion/admin_listener.rb +207 -0
  23. data/lib/hyperion/admin_middleware.rb +36 -7
  24. data/lib/hyperion/cli.rb +310 -11
  25. data/lib/hyperion/config.rb +440 -14
  26. data/lib/hyperion/connection.rb +679 -22
  27. data/lib/hyperion/deprecations.rb +81 -0
  28. data/lib/hyperion/dispatch_mode.rb +165 -0
  29. data/lib/hyperion/fiber_local.rb +75 -13
  30. data/lib/hyperion/h2_admission.rb +77 -0
  31. data/lib/hyperion/h2_codec.rb +499 -0
  32. data/lib/hyperion/http/page_cache.rb +122 -0
  33. data/lib/hyperion/http/sendfile.rb +696 -0
  34. data/lib/hyperion/http2/native_hpack_adapter.rb +70 -0
  35. data/lib/hyperion/http2_handler.rb +618 -19
  36. data/lib/hyperion/io_uring.rb +317 -0
  37. data/lib/hyperion/lint_wrapper_pool.rb +126 -0
  38. data/lib/hyperion/master.rb +96 -9
  39. data/lib/hyperion/metrics/path_templater.rb +68 -0
  40. data/lib/hyperion/metrics.rb +256 -0
  41. data/lib/hyperion/prometheus_exporter.rb +150 -0
  42. data/lib/hyperion/request.rb +13 -0
  43. data/lib/hyperion/response_writer.rb +477 -16
  44. data/lib/hyperion/runtime.rb +195 -0
  45. data/lib/hyperion/server/route_table.rb +179 -0
  46. data/lib/hyperion/server.rb +519 -55
  47. data/lib/hyperion/static_preload.rb +133 -0
  48. data/lib/hyperion/thread_pool.rb +61 -7
  49. data/lib/hyperion/tls.rb +343 -1
  50. data/lib/hyperion/version.rb +1 -1
  51. data/lib/hyperion/websocket/close_codes.rb +71 -0
  52. data/lib/hyperion/websocket/connection.rb +876 -0
  53. data/lib/hyperion/websocket/frame.rb +356 -0
  54. data/lib/hyperion/websocket/handshake.rb +525 -0
  55. data/lib/hyperion/worker.rb +111 -9
  56. data/lib/hyperion.rb +137 -3
  57. metadata +50 -1
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../h2_codec'
4
+
5
+ module Hyperion
6
+ module Http2
7
+ # Phase 10 (RFC §3 Phase 6c, 2.2.0) — adapter shim that exposes the
8
+ # Rust HPACK encoder/decoder behind the same call surface
9
+ # `protocol-http2`'s connection uses today (`#encode_headers(headers)`
10
+ # → bytes, `#decode_headers(bytes)` → array of [name, value]).
11
+ #
12
+ # The adapter is constructed once per HTTP/2 connection, holds an
13
+ # `Hyperion::H2Codec::Encoder` and `Decoder` (each owns its own RFC 7541
14
+ # dynamic table), and is consulted only from the encode/decode
15
+ # serialization point inside `protocol-http2::Connection`. The framer,
16
+ # stream state machine, flow control, and HEADERS/CONTINUATION
17
+ # framing all stay in `protocol-http2` — Phase 10's scope is the
18
+ # HPACK byte-pump only. Replacing the framer in Rust is left for a
19
+ # future Phase 6d.
20
+ #
21
+ # When `Hyperion::H2Codec.available?` is false (no Rust toolchain at
22
+ # gem install, ABI mismatch, JRuby, etc.) callers MUST NOT
23
+ # construct `NativeHpackAdapter` — the substitution layer in
24
+ # `Http2Handler#build_server` skips installation in that case and
25
+ # the connection keeps using `protocol-http2`'s pure-Ruby
26
+ # Compressor/Decompressor.
27
+ #
28
+ # Headers are passed in/returned as `[[name_string, value_string], …]`
29
+ # — the same shape `protocol-http2` already uses internally, so the
30
+ # substitution is byte-for-byte transparent at the protocol-http2
31
+ # boundary.
32
+ class NativeHpackAdapter
33
+ # @raise [RuntimeError] if the native codec isn't loaded.
34
+ def initialize
35
+ unless Hyperion::H2Codec.available?
36
+ raise 'NativeHpackAdapter requires Hyperion::H2Codec.available? — guard at the call site'
37
+ end
38
+
39
+ @encoder = Hyperion::H2Codec::Encoder.new
40
+ @decoder = Hyperion::H2Codec::Decoder.new
41
+ end
42
+
43
+ # Encode a header block via the native HPACK encoder. The
44
+ # encoder's dynamic table persists across calls (HPACK is
45
+ # stateful per direction per connection), so two HEADERS frames
46
+ # encoded back-to-back on the same adapter share table state
47
+ # exactly as RFC 7541 requires.
48
+ #
49
+ # @param headers [Array<Array(String, String)>]
50
+ # @param buffer [String] optional output buffer; bytes are
51
+ # appended so the Rust encoder's output appends to whatever
52
+ # the caller already accumulated. Returned for chaining.
53
+ # @return [String] the buffer (with newly-encoded bytes appended).
54
+ def encode_headers(headers, buffer = String.new.b)
55
+ bytes = @encoder.encode(headers)
56
+ buffer << bytes
57
+ buffer
58
+ end
59
+
60
+ # Decode a HEADERS/CONTINUATION block via the native HPACK
61
+ # decoder. Updates the decoder's dynamic table.
62
+ #
63
+ # @param data [String] the wire bytes for one header block.
64
+ # @return [Array<Array(String, String)>]
65
+ def decode_headers(data)
66
+ @decoder.decode(data)
67
+ end
68
+ end
69
+ end
70
+ end