class
FetchSession
class FetchSession
Connection settings shared by the fetch() calls that name it, and the keep-alive connection pool they share. Connections are never shared between two sessions, or between a session and plain fetch().
const session = new Bun.FetchSession({
proxy: { url: "http://proxy.internal:8080", respectNoProxy: false },
tls: { ca: await Bun.file("corp-ca.pem").text() },
});
const response = await session.fetch("https://example.com");
// the same request, as an option of the global fetch():
await fetch("https://example.com", { session });- readonly fetch: (input: string | URL | Request, init?: BunFetchRequestInit) => Promise<Response>
fetch()with this session. The function is bound: hand it to anything that takes afetch. Asessionininitdoes not replace this one.It has no
preconnect, so where an option is typedtypeof fetch(which in Bun includesfetch.preconnect), passsession.fetch as typeof fetch.const client = new SomeClient({ fetch: session.fetch }); Close the idle connections in this session's pool. Requests in flight finish, and the session stays usable.