Repository navigation
refactor(http2,http3): pull repeated wire and header code into inline helpers - #366
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor only (one small fix noted below): repeated wire/header code in the HTTP/2 and HTTP/3 paths moves into
static inlinehelpers.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:h2_make_frame_header) and both frame-header parsers;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()backsh2_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-Typefor five protocol error responses (malformed request ×2, payload too large, incomplete sequenced body, too early).Content-Typeonlyif (st->res->headers). A fresh response starts withheaders == NULL, so these errors went out without a content type. They now always carryapplication/json.Diff: 5 files, +101 / −294, plus the two new headers.
Checks
WERROR=1build.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).