feat!: use Fetch API for HTTP transport - #654
Open
kahirokunn wants to merge 5 commits into
Open
Conversation
kahirokunn
force-pushed
the
http-transport-fetch
branch
2 times, most recently
from
August 17, 2026 16:15
92f1278 to
8077cd8
Compare
Author
|
@lholmquist Hi ✋ would you mind taking a look when you have a chance? Thank you 🙏 |
kahirokunn
force-pushed
the
http-transport-fetch
branch
from
August 18, 2026 13:45
8077cd8 to
ca4e0fd
Compare
Signed-off-by: kahirokunn <okinakahiro@gmail.com>
Signed-off-by: kahirokunn <okinakahiro@gmail.com>
BREAKING CHANGE: httpTransport() is built on the Fetch API, which changes
what it resolves with, what it sends, and what it needs from its environment.
- A response that is not 2xx rejects with an HTTPTransportError instead of
resolving, so a receiver which refused an event no longer looks like one
that accepted it. Its kind tells a bad status from an abort and from a
request that never reached a response
- A send resolves with { response, body } rather than { body, headers }.
response is the native Fetch Response, so its headers are a Fetch Headers
instance and not Node's IncomingHttpHeaders
- Redirects are no longer followed. fetchOptions: { redirect: "follow" }
restores that, keeping in mind that Fetch preserves the CloudEvent POST
and its body only for 307 and 308
- Options declares headers and signal, which used to fall under an index
signature that resolved to unknown, so TypeScript now checks them
- Proxies and custom CAs set on http.globalAgent no longer apply, since
Fetch does not use those agents. On Node.js an undici dispatcher passed
through fetchOptions is the equivalent
See API_TRANSITION_GUIDE.md for the migration steps.
Signed-off-by: kahirokunn <okinakahiro@gmail.com>
Signed-off-by: kahirokunn <okinakahiro@gmail.com>
Signed-off-by: kahirokunn <okinakahiro@gmail.com>
kahirokunn
force-pushed
the
http-transport-fetch
branch
from
August 18, 2026 14:38
ca4e0fd to
da9ed1a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes: #564
Fixes: #534
Proposed Changes
Use the Fetch API for the built-in HTTP transport, add opt-in retries with
withRetry(), and add configurable emitter timeouts withwithTimeout().Description
httpTransport()now resolves successful sends with the native FetchResponseand the handled body. Non-2xx responses, aborts, and network failures reject withHTTPTransportError. The transport accepts Fetch headers and options, response handlers, and transport-wide or per-send abort signals. Redirects fail by default unless enabled withfetchOptions.redirect.withRetry()retries common temporary HTTP failures with capped randomized exponential backoff and honorsRetry-Afterfor 429 and 503 responses. Every attempt sends the same CloudEvent, so receivers should handle duplicates.withTimeout()gives each emitter invocation a configurable deadline and combines it with a caller-provided abort signal. When composed insidewithRetry(), each attempt receives a fresh timeout; when composed outside it, one timeout covers every attempt and retry backoff. Timed-out HTTP sends reject with anHTTPTransportErrorwhosekindisaborted, and the default retry policy does not retry them.See
API_TRANSITION_GUIDE.mdfor the breaking changes and migration examples.