Skip to content

fix(wrapper): hold headers until request body buffering completes - #60

Merged
johnlanni merged 3 commits into
mainfrom
fix/buffered-request-header-iteration
Nov 11, 2026
Merged

johnlanni merged 3 commits into
mainfrom
fix/buffered-request-header-iteration

Conversation

@johnlanni

@johnlanni johnlanni commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

When transformer runs before an asynchronous rate limiter, returning Continue from its header handler lets the limiter resume Envoy's shared body buffer while transformer is still buffering the upload. A real gateway reproduction forwards the original JSON upstream instead of applying the configured body transformation.

Hold headers with HeaderStopIteration only when the current request actually uses buffered body processing, its header handler returned Continue, and it does not require Expect/Upgrade/CONNECT negotiation. Honor DontReadRequestBody, streaming selection, existing binary/encoding/WebSocket opt-outs, and explicit header actions including both StopAll variants. Complete buffered request delivery once on either DATA end-of-stream or trailers, retaining legacy fail-open reads and required-body fail-closed behavior. Update the example assertions and test-host implicit initialization for the intended header pause.

Compatibility

  • Requests carrying an Expect: 100-continue token, valid Upgrade headers, or the CONNECT method retain their original header action, including when RequireRequestBody() is set. Only the new automatic header hold is bypassed; body settings and explicit plugin actions are unchanged. Connection/Expect values use case-insensitive complete-token matching. These compatibility paths retain the previous shared-buffer behavior and do not gain the new header barrier.
  • When HCM generates 100 locally and removes Expect before filters run, ordinary complete-body buffering still holds subsequent headers.
  • Subsequent filters' header handlers now run after complete-body processing for requests that need buffering; external calls that previously overlapped the upload are consequently delayed.
  • Explicit plugin pauses and asynchronous body callback actions are preserved. Direct plugin calls to ResumeHttpRequest() are still the plugin's responsibility; the wrapper does not intercept them.
  • Request trailer completion is needed for the new header hold to finish correctly. This overlaps the request-side portion of fix(wrapper): finalize HTTP bodies on trailers and support streaming trailer pauses #57; response trailer APIs and response processing are outside this change.
  • Existing published Wasm binaries are unaffected until rebuilt with the updated SDK.

Verification

  • New buffered-body regression tests fail against the original implementation and pass with this change. Coverage includes buffered/streaming selection, missing header callbacks, opt-outs, required-body overrides, explicit StopAll actions, multi-chunk and empty bodies, trailers, read failures, and asynchronous body pause/resume.
  • New handshake regressions fail against the original PR implementation (b06c410) and pass with the protocol exemptions. The tests preserve required body delivery and explicit Stop/StopAll actions, and check token lists and false substring matches. Independent compatibility re-review found no remaining P0/P1 in this patch.
  • GOMAXPROCS=4 go test -p 4 -race ./pkg/... passed.
  • GOMAXPROCS=4 go test -p 4 ./... passed in all five example modules; request-block checks both native Go and compiled Wasm, including implicit header initialization.
  • go vet ./... passed in the root and all example modules; gofmt and git diff --check passed.
  • Real community transformer and ai-token-ratelimit, built against this SDK, passed the committed integration script on Higress Envoy 1.36.12. Companion Higress checkout: d388d06a92dd125bbe99330888690fd6deeb352f; baseline SDK: 580c182.
Real gateway case Observed result
Original SDK, split JSON upload Redis callback and upstream body forwarding happen before upload completion; upstream receives the untransformed original JSON
Fixed SDK, split JSON upload No early successor activity; upstream receives transformed JSON
Fixed SDK, chunked upload ending in trailers Full body transformed and forwarded
Fixed SDK, binary opt-out Original bytes forwarded, retaining early header processing
Fixed SDK, rate-limit rejection HTTP 429, zero upstream requests
Upstream 100 Continue, original/fixed SDK Receive 100 before uploading any body; final body response unchanged
Local 100 Continue, fixed SDK Receive local 100 while subsequent headers remain held, checked during an observation window before uploading
WebSocket, including RequireRequestBody and Connection token lists Receive 101 before sending data, matching original SDK
CONNECT, with and without RequireRequestBody Receive 200 before sending data, matching original SDK

Reproduce with the committed script (requires Docker, Go, redis-server, redis-cli, and a Higress checkout):

python3 test/integration/buffered_request_body.py \
  --higress-root /path/to/higress \
  --envoy-image higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/gateway:1cf20e40264ffc6b10919f0005edc135af1683c4 \
  --work-dir /tmp/wasm-go-body-check \
  --baseline-sdk /path/to/unpatched/wasm-go

The script runs 21 original/fixed gateway cases when a baseline SDK is supplied. It uses temporary module files, a complete-body Wasm handshake fixture, isolated loopback listeners and disabled hot restart; records results and Envoy logs; and cleans up only its own containers/processes. Runtime handshake tests verify negotiation; required-body byte delivery is checked separately in Go unit tests. This integration check is manual; the ordinary SDK tests continue to run in CI.

AI-assisted implementation and verification with OpenAI Codex.

johnlanni and others added 3 commits November 11, 2026 12:11
Signed-off-by: zty98751 <zty98751@alibaba-inc.com>
Signed-off-by: zty98751 <zty98751@alibaba-inc.com>
Signed-off-by: johnlanni <ztywto@qq.com>
@johnlanni
johnlanni merged commit 647ef40 into main Nov 11, 2026
4 checks passed
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