From 3c9fca7c339753fa6d6430fb5659e6d11fc20997 Mon Sep 17 00:00:00 2001 From: killa Date: Wed, 4 Dec 2024 19:17:07 +0800 Subject: [PATCH] feat: exports undici (#554) ## Summary by CodeRabbit - **Bug Fixes** - Improved error handling and diagnostics publishing for fetch operations, ensuring errors are reported through the correct channel. - **New Features** - Enhanced type definitions with new types for better type safety: `BodyInit`, `ResponseInit`, `Headers`, and `FormData`. - Optimized handling of HTTP requests with caching for socket-based clients. - **Documentation** - Updated export statements to maintain compatibility with existing libraries while enhancing functionality. --- src/fetch.ts | 4 ++-- src/index.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fetch.ts b/src/fetch.ts index 5c51b083..f47fd98d 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -223,11 +223,11 @@ export class FetchFactory { res = await UndiciFetch(input, init); }); } catch (e: any) { - channels.response.publish({ + channels.fetchResponse.publish({ fetch: fetchMeta, error: e, } as FetchResponseDiagnosticsMessage); - channels.fetchResponse.publish({ + channels.response.publish({ request: reqMeta, response: urllibResponse, error: e, diff --git a/src/index.ts b/src/index.ts index 0d4c5f28..ded47ff3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,7 +44,8 @@ export { MockAgent, ProxyAgent, Agent, Dispatcher, setGlobalDispatcher, getGlobalDispatcher, Request, RequestInfo, RequestInit, - Response, + Response, BodyInit, ResponseInit, + Headers, FormData, } from 'undici'; // HttpClient2 is keep compatible with urllib@2 HttpClient2 export {