镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix: preserve raw headers in dispatch handler bridge - #5345

Merged
mcollina merged 1 commit into
v7.xfrom
fix/5341-legacy-raw-headers
Jun 3, 2026
Merged

mcollina merged 1 commit into
v7.xfrom
fix/5341-legacy-raw-headers

Conversation

@mcollina

@mcollina mcollina commented Jun 3, 2026

Copy link
Copy Markdown
Member

Description

Preserve rawHeaders and rawTrailers on the synthetic controller used by UnwrapHandler when bridging modern dispatch handlers to the legacy handler interface.

This keeps Node.js bundled fetch compatible with an imported Undici v7 Agent, so response headers remain visible and compressed bodies continue to be decoded.

Fixes: #5341

Changes

  • store rawHeaders on the controller before invoking onRequestUpgrade / onResponseStart
  • store rawTrailers before invoking onResponseEnd
  • expose the optional controller fields in types/dispatcher.d.ts
  • add a regression test covering Node.js global fetch with both the global dispatcher and an explicit dispatcher: new Agent()

Testing

  • npm run lint -- lib/handler/unwrap-handler.js test/node-test/global-dispatcher-version.js types/dispatcher.d.ts
  • npx borp -p "test/node-test/global-dispatcher-version.js"
  • source ~/.nvm/nvm.sh && nvm use 26.3.0 >/dev/null && npx borp -p "test/node-test/global-dispatcher-version.js"

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.90%. Comparing base (d7aeee3) to head (7ecea4c).

Additional details and impacted files
@@            Coverage Diff             @@
##             v7.x    #5345      +/-   ##
==========================================
- Coverage   92.91%   92.90%   -0.01%     
==========================================
  Files         112      112              
  Lines       35837    35843       +6     
==========================================
+ Hits        33297    33299       +2     
- Misses       2540     2544       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina
mcollina merged commit 3e17d92 into v7.x Jun 3, 2026
68 of 70 checks passed
@mcollina
mcollina deleted the fix/5341-legacy-raw-headers branch June 3, 2026 11:53
@github-actions github-actions Bot mentioned this pull request Jun 3, 2026
QuiiBz added a commit to vercel/sandbox that referenced this pull request Jun 4, 2026
Closes #198

Update the Undici version we use to fix an issue where using Undici v7
`Agent` with a Undici v8 `fetch` (e.g. using Node.js 26 with the global,
bundled `fetch`) would cause response headers to be dropped, and
response body to not be decompressed

Upstream Undici fix: nodejs/undici#5345
griffinwork40 added a commit to griffinwork40/agent-afk that referenced this pull request Sep 29, 2026
…2525) (#2535)

* fix(deps): raise undici floor to ^7.27.1; add Node 26 CI leg (issue #2525)

## Problem

On Node 26.0.0, importing npm undici 7.27.0 installs a broken global dispatcher
that corrupts built-in fetch: gzip-encoded responses lose all headers and arrive
as a still-compressed buffer. The Anthropic SDK receives a string instead of JSON
and `oneShotCompletion` throws `response.content is not iterable`. Both the global
dispatcher slot and the per-request `dispatcher: new Agent()` path in
`src/http-client/egress-guard.ts` (web_scrape / web_request) are affected.

Root cause: a bug in undici 7.27.0 only, where `UnwrapController` loses
`rawHeaders`/`rawTrailers` in the dispatch handler bridge. Fixed in 7.27.1 by
nodejs/undici#5345.

## Changes

- package.json: undici ^7.27.0 -> ^7.27.1 (resolves 7.30.0)
- pnpm-lock.yaml: updated specifier and snapshot
- .github/workflows/ci.yml: add test-node26 job
- src/http-client/undici-gzip-compat.test.ts: regression test

Fixes #2525

* test(http-client): make the undici gzip-bridge regression test discriminate

The first version never loaded npm undici, so Node's built-in fetch ran
through its own bundled dispatcher and the test passed on the broken
undici 7.27.0 + Node 26.0.0 pair as well.

Now both paths agent-afk depends on go through an npm-undici Agent:
- global slot: setGlobalDispatcher(new Agent()), with the prior
  Symbol.for('undici.globalDispatcher.{1,2}') values restored afterwards
  (vitest's worker may already have filled the slot with the built-in
  Agent, so relying on import side effects is not enough)
- per-request: `dispatcher: new Agent()`, the shape egress-guard.ts uses

Verified on Node 26.0.0: both cases fail with undici 7.27.0 installed
and pass with 7.30.0. They pass on Node 24.11 with 7.30.0.

Refs #2525

---------

Co-authored-by: Griffin Long <griffinlong@users.noreply.github.com>
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.

4 participants