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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4768 -0
- data/README.md +222 -13
- data/ext/hyperion_h2_codec/Cargo.lock +7 -0
- data/ext/hyperion_h2_codec/Cargo.toml +33 -0
- data/ext/hyperion_h2_codec/extconf.rb +73 -0
- data/ext/hyperion_h2_codec/src/frames.rs +140 -0
- data/ext/hyperion_h2_codec/src/hpack/huffman.rs +161 -0
- data/ext/hyperion_h2_codec/src/hpack.rs +457 -0
- data/ext/hyperion_h2_codec/src/lib.rs +296 -0
- data/ext/hyperion_http/extconf.rb +28 -0
- data/ext/hyperion_http/h2_codec_glue.c +408 -0
- data/ext/hyperion_http/page_cache.c +1125 -0
- data/ext/hyperion_http/parser.c +473 -38
- data/ext/hyperion_http/sendfile.c +982 -0
- data/ext/hyperion_http/websocket.c +493 -0
- data/ext/hyperion_io_uring/Cargo.lock +33 -0
- data/ext/hyperion_io_uring/Cargo.toml +34 -0
- data/ext/hyperion_io_uring/extconf.rb +74 -0
- data/ext/hyperion_io_uring/src/lib.rs +316 -0
- data/lib/hyperion/adapter/rack.rb +370 -42
- data/lib/hyperion/admin_listener.rb +207 -0
- data/lib/hyperion/admin_middleware.rb +36 -7
- data/lib/hyperion/cli.rb +310 -11
- data/lib/hyperion/config.rb +440 -14
- data/lib/hyperion/connection.rb +679 -22
- data/lib/hyperion/deprecations.rb +81 -0
- data/lib/hyperion/dispatch_mode.rb +165 -0
- data/lib/hyperion/fiber_local.rb +75 -13
- data/lib/hyperion/h2_admission.rb +77 -0
- data/lib/hyperion/h2_codec.rb +499 -0
- data/lib/hyperion/http/page_cache.rb +122 -0
- data/lib/hyperion/http/sendfile.rb +696 -0
- data/lib/hyperion/http2/native_hpack_adapter.rb +70 -0
- data/lib/hyperion/http2_handler.rb +618 -19
- data/lib/hyperion/io_uring.rb +317 -0
- data/lib/hyperion/lint_wrapper_pool.rb +126 -0
- data/lib/hyperion/master.rb +96 -9
- data/lib/hyperion/metrics/path_templater.rb +68 -0
- data/lib/hyperion/metrics.rb +256 -0
- data/lib/hyperion/prometheus_exporter.rb +150 -0
- data/lib/hyperion/request.rb +13 -0
- data/lib/hyperion/response_writer.rb +477 -16
- data/lib/hyperion/runtime.rb +195 -0
- data/lib/hyperion/server/route_table.rb +179 -0
- data/lib/hyperion/server.rb +519 -55
- data/lib/hyperion/static_preload.rb +133 -0
- data/lib/hyperion/thread_pool.rb +61 -7
- data/lib/hyperion/tls.rb +343 -1
- data/lib/hyperion/version.rb +1 -1
- data/lib/hyperion/websocket/close_codes.rb +71 -0
- data/lib/hyperion/websocket/connection.rb +876 -0
- data/lib/hyperion/websocket/frame.rb +356 -0
- data/lib/hyperion/websocket/handshake.rb +525 -0
- data/lib/hyperion/worker.rb +111 -9
- data/lib/hyperion.rb +137 -3
- 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
|