Skip to content

feat(wrapper): add per-request body delivery requirement - #59

Merged
johnlanni merged 4 commits into
mainfrom
feat/wrapper-require-body
Nov 1, 2026
Merged

johnlanni merged 4 commits into
mainfrom
feat/wrapper-require-body

Conversation

@johnlanni

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in, per-request body-delivery declaration to the wrapper: RequireRequestBody() on HttpContext.

Plugins that perform body-dependent processing (digest validation, body-aware authorization) currently depend on implicit body availability. The wrapper's automatic binary-content and websocket skips can suppress body delivery based on request headers alone, which those plugins cannot distinguish from "no body". The new declaration makes the contract explicit:

  • When declared, the plugin's body callback is invoked with the raw buffered bytes regardless of Content-Type (octet-stream, grpc) or any Content-Encoding (including identity).
  • When declared and the body cannot be obtained or buffered, the wrapper fails closed with a local reply instead of continuing silently.
  • Plugins that never declare it keep the exact legacy behavior — no ecosystem-wide default change.

Tests

  • binary content-type + declaration → callback receives raw bytes
  • Content-Encoding identity/gzip + declaration → same
  • websocket + declaration → request-body path still delivered (response path untouched)
  • buffer acquisition failure + declaration → local reply, no silent continue
  • no declaration → legacy skip behavior preserved bit-for-bit

go build ./... && go test ./pkg/... green.

Signed-off-by: johnlanni <ztywto@qq.com>
Signed-off-by: johnlanni <ztywto@qq.com>
Signed-off-by: johnlanni <ztywto@qq.com>
Fail invalid required-body opt-ins and preserve exactly-once empty-body
delivery when request headers pause.

Signed-off-by: johnlanni <ztywto@qq.com>
@johnlanni
johnlanni merged commit 580c182 into main Nov 1, 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