-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix socket info in response (#555)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced the `BaseAgent` class with enhanced asynchronous local storage capabilities. - Updated `HttpAgent` to extend `BaseAgent`, improving address validation and error handling during dispatch operations. - **Bug Fixes** - Enhanced validation in the `dispatch` method of `HttpAgent` to ensure hostname validity. - **Tests** - Added a new assertion in the fetch tests to verify the local address of the response socket. - **Chores** - Removed the `fetchOpaqueInterceptor` function and associated imports to streamline the codebase. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
5 changed files
with
41 additions
and
29 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,27 @@ | ||
import { | ||
Agent, | ||
Dispatcher, | ||
} from 'undici'; | ||
import { AsyncLocalStorage } from 'node:async_hooks'; | ||
import { FetchOpaque } from './FetchOpaqueInterceptor.js'; | ||
|
||
export interface BaseAgentOptions extends Agent.Options { | ||
opaqueLocalStorage?: AsyncLocalStorage<FetchOpaque>; | ||
} | ||
|
||
export class BaseAgent extends Agent { | ||
#opaqueLocalStorage?: AsyncLocalStorage<FetchOpaque>; | ||
|
||
constructor(options: BaseAgentOptions) { | ||
super(options); | ||
this.#opaqueLocalStorage = options.opaqueLocalStorage; | ||
} | ||
|
||
dispatch(options: Agent.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean { | ||
const opaque = this.#opaqueLocalStorage?.getStore(); | ||
if (opaque) { | ||
(handler as any).opaque = opaque; | ||
} | ||
return super.dispatch(options, 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
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