Skip to content

refactor(core, fetch, node): share getRequiredStandardBodyHint from core - #177

Merged
dinwwwh merged 1 commit into
mainfrom
claude/youthful-einstein-y8ilnu
Oct 26, 2026
Merged

dinwwwh merged 1 commit into
mainfrom
claude/youthful-einstein-y8ilnu

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Oct 26, 2026

Copy link
Copy Markdown
Member

Summary

toFetchBody and toNodeHttpBody each had their own copy of a private _requiredBodyHint helper. It decides whether a non-binary body needs a standard-server hint. This PR moves it to core as getRequiredStandardBodyHint(hint, headers), next to resolveStandardBodyHint, 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 undefined when they already resolve to hint. For example, JSON sent as application/problem+json returns 'json'; JSON sent as application/json; charset=utf-8 returns undefined.

Changes

  • packages/core/src/utils.ts: adds the exported getRequiredStandardBodyHint, built on resolveStandardBodyHint.
  • packages/fetch/src/body.ts, packages/node/src/body.ts: drop _requiredBodyHint and 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 a standard-server header that is already set.
  • packages/core/README.md: one paragraph with an example, after the resolveStandardBodyHint section.

Notes for reviewers

  • The core function ignores any standard-server header already in headers, 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.
  • This adds a new public export to @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.
  • The Bun tests (tests/bun) pass.

Generated by Claude Code

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
@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026

Copy link
Copy Markdown
@standard-server/aws-lambda

npm i https://pkg.pr.new/@standard-server/aws-lambda@177

@standard-server/core

npm i https://pkg.pr.new/@standard-server/core@177

@standard-server/fastify

npm i https://pkg.pr.new/@standard-server/fastify@177

@standard-server/fetch

npm i https://pkg.pr.new/@standard-server/fetch@177

@standard-server/node

npm i https://pkg.pr.new/@standard-server/node@177

@standard-server/peer

npm i https://pkg.pr.new/@standard-server/peer@177

@standard-server/shared

npm i https://pkg.pr.new/@standard-server/shared@177

commit: 9250412

@codspeed

codspeed Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 5 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 26 untouched benchmarks
⏩ 108 skipped benchmarks1


Comparing claude/youthful-einstein-y8ilnu (9250412) with main (64da7db)2

Open in CodSpeed

Footnotes

  1. 108 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (6041bd0) during the generation of this report, so 64da7db was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Core extraction — getRequiredStandardBodyHint(hint, headers) is now exported from packages/core/src/utils.ts, built on resolveStandardBodyHint.
  • Adapter dedup — packages/fetch/src/body.ts and packages/node/src/body.ts drop their private _requiredBodyHint copies and call the core function at the same four sites (none, url-search-params, event-stream, json).
  • Deliberate standard-server exclusion — the core helper forwards only content-type/content-length/content-disposition, so a pre-existing standard-server header cannot influence the result. Both adapters already set headers['standard-server'] = undefined immediately before each call, so the emitted headers are byte-for-byte unchanged.
  • Tests and docs — a new getRequiredStandardBodyHint table plus a README paragraph whose examples I verified against the implementation.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@dinwwwh
dinwwwh merged commit 7636c00 into main Oct 26, 2026
13 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.

2 participants