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,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyperion
4
+ module WebSocket
5
+ # 2.5-A — RFC 6455 §7.4.1 close-code validation.
6
+ #
7
+ # The close-frame status code is a 16-bit unsigned integer at the
8
+ # start of the close-frame payload. Only specific ranges are valid
9
+ # on the wire, and a server that sees an invalid one MUST respond
10
+ # with close 1002 (Protocol Error) per RFC 6455 §7.4 + §7.4.1
11
+ # rather than echoing the bad code back.
12
+ #
13
+ # The IANA-assigned ranges as of RFC 6455:
14
+ #
15
+ # 1000–1003 Defined (Normal, Going Away, Protocol Error,
16
+ # Unsupported Data)
17
+ # 1004 Reserved (no defined meaning — not on wire)
18
+ # 1005 No Status Recv'd (synthetic — MUST NOT appear on wire)
19
+ # 1006 Abnormal Closure (synthetic — MUST NOT appear on wire)
20
+ # 1007–1015 Defined (Invalid Frame Payload, Policy
21
+ # Violation, Message Too Big,
22
+ # Mandatory Ext, Internal Error,
23
+ # Service Restart, Try Again Later,
24
+ # Bad Gateway, TLS handshake)
25
+ # 1016–2999 Reserved for IETF future use (not on wire)
26
+ # 3000–3999 Registered library / framework codes
27
+ # 4000–4999 Application-private codes
28
+ # <1000, >=5000 Invalid (out of any defined range)
29
+ module CloseCodes
30
+ # Whitelisted code ranges that MAY appear on the wire from a peer.
31
+ VALID_RANGES = [
32
+ (1000..1003),
33
+ (1007..1015),
34
+ (3000..3999),
35
+ (4000..4999)
36
+ ].freeze
37
+
38
+ # Reserved-for-IETF range — not currently assigned, MUST NOT appear
39
+ # on the wire, MUST be rejected with 1002.
40
+ RESERVED_RANGE = (1016..2999)
41
+
42
+ # Synthetic codes that MUST NOT appear on the wire (RFC 6455 §7.4.1).
43
+ # 1005 = "No Status Received", 1006 = "Abnormal Closure". Both are
44
+ # produced internally by an endpoint when no close code was carried
45
+ # by the close frame, never sent by an endpoint.
46
+ NO_STATUS_ON_WIRE = [1005, 1006].freeze
47
+
48
+ # Validate a peer-supplied close code.
49
+ #
50
+ # @param code [Integer]
51
+ # @return [Symbol] one of:
52
+ # :ok — code is in a valid wire range, accept it
53
+ # :no_status_on_wire — code is 1005 / 1006 (synthetic only)
54
+ # :reserved — code is in 1016–2999 (IETF reserved)
55
+ # :invalid — code is outside every defined range
56
+ def self.validate(code)
57
+ return :no_status_on_wire if NO_STATUS_ON_WIRE.include?(code)
58
+ return :ok if VALID_RANGES.any? { |r| r.cover?(code) }
59
+ return :reserved if RESERVED_RANGE.cover?(code)
60
+
61
+ :invalid
62
+ end
63
+
64
+ # Convenience predicate — true if the peer's close code violates
65
+ # RFC 6455 §7.4.1 in any way.
66
+ def self.invalid?(code)
67
+ validate(code) != :ok
68
+ end
69
+ end
70
+ end
71
+ end