Skip to content

refactor(http2,http3): pull repeated wire and header code into inline helpers - #366

Merged
gg582 merged 1 commit into
devfrom
refactor/h2-h3-inline-helpers
Oct 12, 2026
Merged

gg582 merged 1 commit into
devfrom
refactor/h2-h3-inline-helpers

Conversation

@gg582

@gg582 gg582 commented Oct 12, 2026

Copy link
Copy Markdown
Member

Refactor only (one small fix noted below): repeated wire/header code in the HTTP/2 and HTTP/3 paths moves into static inline helpers.

HTTP/2

  • src/net/http/h2_wire.h (new, private): h2_put_u24/u32/u31, h2_get_u16/u24/u32/u31. Replaces ~20 hand-written shift/mask sequences:
    • frame header write (h2_make_frame_header) and both frame-header parsers;
    • GOAWAY, RST_STREAM, WINDOW_UPDATE and PUSH_PROMISE payloads;
    • both WINDOW_UPDATE parsers and SETTINGS parsing;
    • the flow-control module's WINDOW_UPDATE builder (http2_flow_control.c).
      The 31-bit variants hold the reserved-bit rule (sent as 0, ignored on receipt) in one place.
  • h2_env_long(): the five env knobs (idle timeout, GOAWAY grace, RST burst/rate, batch bytes) share one parser. getenv("CWIST_...") stays at each call site so the runtime-knob gate (docs(config): document every CWIST_* runtime variable and gate it (#340) #360) still sees them; defaults and minimums are unchanged.
  • h2_now_ns() backs h2_now_ms() / h2_now_us().

HTTP/3

  • src/net/http/h3_hdr_out.h (new, private): h3_hdr_out_add() / h3_hdr_out_add_str() append one field to an lsxpack header set (name, 2 spare bytes, value) with slot and buffer bounds checked once. Used by server response headers, server push, and client request headers — 13 copies of the same 6 lines.
  • h3_json_error(): status + JSON body + Content-Type for five protocol error responses (malformed request ×2, payload too large, incomplete sequenced body, too early).
    • Small fix: the old code added Content-Type only if (st->res->headers). A fresh response starts with headers == NULL, so these errors went out without a content type. They now always carry application/json.

Diff: 5 files, +101 / −294, plus the two new headers.

Checks

  • WERROR=1 build.
  • test_http2, test_http2_flow_control, test_http2_prebuffer, test_http3, test_webtransport, test_webtransport_client_api, test_grpc, test_grpc_append_error, test_grpc_channel, test_grpc_client, test_grpc_stream: all pass.
  • scripts/ci/h2spec_gate.sh: no new failures vs the baseline (146 tests, 103 passed — same as dev).
  • clang-format applied to the changed regions only; formatter churn in unrelated code was reverted.

… helpers

HTTP/2
- src/net/http/h2_wire.h: h2_put_u24/u32/u31 and h2_get_u16/u24/u32/u31
  replace ~20 hand-written shift/mask sequences: the frame header, GOAWAY,
  RST_STREAM, WINDOW_UPDATE and PUSH_PROMISE payloads, both frame-header
  parsers, both WINDOW_UPDATE parsers, SETTINGS parsing, and the flow-control
  module's WINDOW_UPDATE builder. The 31-bit helpers carry the reserved-bit
  rule (sent as 0, ignored on receipt) in one place.
- h2_env_long(): the five env knobs (idle timeout, GOAWAY grace, RST burst and
  rate, batch bytes) share one parser; getenv("CWIST_...") stays at each call
  site for the runtime-knob gate. Defaults and minimums are unchanged.
- h2_now_ns() backs h2_now_ms()/h2_now_us().

HTTP/3
- src/net/http/h3_hdr_out.h: h3_hdr_out_add()/_add_str() append one field to
  an lsxpack header set ("name", 2 spare bytes, "value") with the slot and
  buffer bounds checked once. Used by the server response headers, server
  push, and the client request headers (13 copies of the same 6 lines).
- h3_json_error(): status + JSON body + Content-Type for the five protocol
  error responses (malformed request x2, payload too large, incomplete
  sequenced body, too early). The old code only added Content-Type when the
  response already had headers; a fresh response has none, so these errors
  went out without it. Now they always carry application/json.

No other behavior change.
@gg582
gg582 merged commit a914a91 into dev Oct 12, 2026
25 checks passed
gg582 added a commit that referenced this pull request Oct 12, 2026
@gg582
gg582 deleted the refactor/h2-h3-inline-helpers branch October 13, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant