Polyfill Headers in proxy with node-fetch #813
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In server/index.ts
nodeFetchandHeaders(asNodeHeaders) fromnode-fetchfetchconstant set tonodeFetch(overridesglobalThis.fetch)Headersconstant set toNodeHeaders(overridesglobalThis.Headers)createCustomFetchfunctionfinalHeaderstoheadersobject fornode-fetchcompatibilityReadableStreamsinceEventSourceexpects web-compatible streamIn package-lock.json and package.json
Motivation and Context
Some users now get a "Headers is undefined" message when connecting to an SSE server. This is likely a result of the recent fix that injects headers that are dynamically introduced in server responses into the response to sent to the client on its transport. That code uses the
Headersinterface, which may not be present in some Node environments.The fix was to use
NodeHeadersfromnode-fetchand also for SSE streams to convert Node streams to webstyleReadableStreams.This fixes #600
How Has This Been Tested?
Tested against both StreamableHttp and SSE versions of the Everything reference server
Breaking Changes
Nope.
Types of changes
Checklist
Additional context