Repository navigation
refactor(core, fetch, node): share getRequiredStandardBodyHint from core - #177
Conversation
The fetch and node encoders each had a private `_requiredBodyHint` deciding whether a body needs a `standard-server` hint. Move it to core as `getRequiredStandardBodyHint(hint, headers)`, next to `resolveStandardBodyHint`, and use it from both adapters. The core helper ignores any `standard-server` header already in `headers`, since its result replaces that header. The adapters already clear it before calling, so their output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CnkTuoTtiaJ5kMjqaesS9M
@standard-server/aws-lambda
@standard-server/core
@standard-server/fastify
@standard-server/fetch
@standard-server/node
@standard-server/peer
@standard-server/shared
commit: |
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Core extraction —
getRequiredStandardBodyHint(hint, headers)is now exported frompackages/core/src/utils.ts, built onresolveStandardBodyHint. - Adapter dedup —
packages/fetch/src/body.tsandpackages/node/src/body.tsdrop their private_requiredBodyHintcopies and call the core function at the same four sites (none,url-search-params,event-stream,json). - Deliberate
standard-serverexclusion — the core helper forwards onlycontent-type/content-length/content-disposition, so a pre-existingstandard-serverheader cannot influence the result. Both adapters already setheaders['standard-server'] = undefinedimmediately before each call, so the emitted headers are byte-for-byte unchanged. - Tests and docs — a new
getRequiredStandardBodyHinttable plus a README paragraph whose examples I verified against the implementation.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Summary
toFetchBodyandtoNodeHttpBodyeach had their own copy of a private_requiredBodyHinthelper. It decides whether a non-binary body needs astandard-serverhint. This PR moves it to core asgetRequiredStandardBodyHint(hint, headers), next toresolveStandardBodyHint, and both adapters now import it from there.The function returns the hint when the content headers alone would make the receiver parse the body as something else, and
undefinedwhen they already resolve tohint. For example, JSON sent asapplication/problem+jsonreturns'json'; JSON sent asapplication/json; charset=utf-8returnsundefined.Changes
packages/core/src/utils.ts: adds the exportedgetRequiredStandardBodyHint, built onresolveStandardBodyHint.packages/fetch/src/body.ts,packages/node/src/body.ts: drop_requiredBodyHintand call the core function at the same four places.packages/core/src/utils.test.ts: tests for headers that already resolve to the hint, headers that would parse as another type, and astandard-serverheader that is already set.packages/core/README.md: one paragraph with an example, after theresolveStandardBodyHintsection.Notes for reviewers
standard-serverheader already inheaders, because its result is meant to replace that header. The old private helper read it. Both adapters already clear the header before calling, so what they send is unchanged.@standard-server/core.Testing
pnpm run check(sherif, oxlint, oxfmt, tsc) passes.vitest run: 1505 tests pass, including the existing fetch and node body tables that check the kept and removed content-types.tests/bun) pass.Generated by Claude Code