feat(dns): added support for a custom lookup function; (#5339)#6
feat(dns): added support for a custom lookup function; (#5339)#6MitchLewis930 wants to merge 1 commit intopr_026_beforefrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for custom DNS lookup functions in the HTTP adapter, allowing users to override the default DNS resolution behavior when making HTTP requests.
Changes:
- Added new utility functions to detect async functions and thenable objects
- Created a
callbackifyhelper to convert async functions to callback-based functions - Modified the HTTP adapter to accept and process custom
lookupandfamilyconfiguration options
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/utils.js | Added utility functions for detecting function types (async, generator) and thenable objects |
| lib/helpers/callbackify.js | New helper to convert async functions to callback-based functions for DNS lookup compatibility |
| lib/adapters/http.js | Integrated custom lookup function support with automatic async-to-callback conversion |
| index.d.cts | Added TypeScript type definitions for the new family and lookup configuration options |
| test/unit/adapters/http.js | Added comprehensive tests for custom DNS lookup functionality including callback and async variants |
| test/module/typings/esm/index.ts | Added TypeScript usage examples for the new lookup configuration |
| if(utils.isString(entry)) { | ||
| entry = [entry, entry.indexOf('.') < 0 ? 6 : 4] | ||
| } else if (!utils.isArray(entry)) { | ||
| throw new TypeError('lookup async function must return an array [ip: string, family: number]]') |
There was a problem hiding this comment.
The error message contains an extra closing bracket. The text should be 'an array [ip: string, family: number]' with only one closing bracket.
| throw new TypeError('lookup async function must return an array [ip: string, family: number]]') | |
| throw new TypeError('lookup async function must return an array [ip: string, family: number]') |
| } catch (err) { | ||
| cb(err); | ||
| } | ||
| }, cb); |
There was a problem hiding this comment.
When the promise rejects (line 12), the callback receives the raw rejection reason which may not have a meaningful error message. Consider wrapping the rejection in a descriptive error or ensuring the rejection value is always an Error object.
| }, cb); | |
| }, (reason) => { | |
| const error = reason instanceof Error ? reason : new Error(String(reason)); | |
| cb(error); | |
| }); |
|
|
||
| if (lookup && utils.isAsyncFn(lookup)) { | ||
| lookup = callbackify(lookup, (entry) => { | ||
| if(utils.isString(entry)) { |
There was a problem hiding this comment.
Missing space after 'if' keyword. The code should follow consistent spacing conventions: if (utils.isString(entry)).
| if(utils.isString(entry)) { | |
| if (utils.isString(entry)) { |
PR_026