Skip to content

Make Headers instantiable from native Headers #1481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pistvan
Copy link

@pistvan pistvan commented Jun 30, 2025

Given, that I have two fetch middlewares:

// FirstMiddleware.js
export function firstMiddleware(req, next) {
  const headers = new Headers(req.headers); // native Headers type
  headers.set('X-Foo', 'bar');
  return next({ ...req, headers });
}

// SecondMiddleware.js
import { Headers } from 'node-fetch';

export function secondMiddleware(req, next) {
  const headers = new Headers(req.headers); // a polyfill type
  headers.set('X-Bar', 'bar');
  return next({ ...req, headers });
}

In SecondMiddleware, the pre-added headers are no longer kept, as the polyfill can not handle the native type, if it is available for any reason.
This PR fixes this issue.

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