-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- keep urllib:request, urllib:response channel message - add urllib:fetch:request, urllib:fetch:response channel message <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Introduced a `FetchFactory` class for enhanced HTTP request management with diagnostics. - Added a new `FetchOpaque` type for tracking request metadata. - Enhanced `HttpClient` with new timing and diagnostics capabilities. - **Bug Fixes** - Improved error handling for socket-related issues in `HttpClient`. - **Documentation** - Expanded public exports for better usability, including new interfaces and constants. - **Tests** - Added unit tests for the new `fetch` functionality to ensure reliability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
8 changed files
with
461 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// const { AsyncLocalStorage } = require('node:async_hooks'); | ||
import { AsyncLocalStorage } from 'node:async_hooks'; | ||
import symbols from './symbols.js'; | ||
import { Dispatcher } from 'undici'; | ||
|
||
// const RedirectHandler = require('../handler/redirect-handler') | ||
|
||
export interface FetchOpaque { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
[symbols.kRequestId]: number; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
[symbols.kRequestStartTime]: number; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
[symbols.kEnableRequestTiming]: number; | ||
} | ||
|
||
// const internalOpaque = { | ||
// [symbols.kRequestId]: requestId, | ||
// [symbols.kRequestStartTime]: requestStartTime, | ||
// [symbols.kEnableRequestTiming]: !!(init.timing ?? true), | ||
// [symbols.kRequestTiming]: timing, | ||
// // [symbols.kRequestOriginalOpaque]: originalOpaque, | ||
// }; | ||
|
||
export interface OpaqueInterceptorOptions { | ||
opaqueLocalStorage: AsyncLocalStorage<FetchOpaque>; | ||
} | ||
|
||
export function fetchOpaqueInterceptor(opts: OpaqueInterceptorOptions) { | ||
const opaqueLocalStorage = opts?.opaqueLocalStorage; | ||
return (dispatch: Dispatcher['dispatch']): Dispatcher['dispatch'] => { | ||
return function redirectInterceptor(opts: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandlers) { | ||
const opaque = opaqueLocalStorage?.getStore(); | ||
(handler as any).opaque = opaque; | ||
return dispatch(opts, handler); | ||
}; | ||
}; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.