Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lookup option to Client, Pool and Agent (#2440) #3139

Closed
wants to merge 1 commit into from

Conversation

hjr3
Copy link

@hjr3 hjr3 commented Apr 19, 2024

We add an optional custom lookup function to that has the same interface as the lookup option in TCP/UDP socket.connect. This allows users of this library to implement their own DNS caching implementation.

This does not preclude the future possibility of including a DNS caching implementation by default.

This relates to...

Rationale

PR #2552 is attempting to add a default dns caching implementation to undici. Instead of trying to first add a default implementation, which is a lot of work, this PR adds the standard lookup option which allows a user to bring their own DNS lookup implementation.

I believe this is a better place to start from because:

  • avoids committing to a default DNS caching implementation
    • there is no one-size DNS caching implementation that fits all use cases
  • users may have other DNS implementation requirement beyond caching
  • this is a smaller change to the undici public interface
  • this follows existing Node.js convention of providing a lookup option

Adding DNS caching is now as easy as:

import CacheableLookup from 'cacheable-lookup';

const cacheable = new CacheableLookup();

new Agent({
  lookup: cacheable.lookup
});

Changes

Features

  • adds an optional lookup option to Client, Pool and Agent

Bug Fixes

N/A

Breaking Changes and Deprecations

N/A

Status

We add an optional custom lookup function to that has the same interface
as the lookup option in TCP/UDP socket.connect. This allows users of
this library to implement their own DNS caching implementation.

This does not preclude the future possibility of including a DNS caching
implementation by default.
Copy link
Member

@ronag ronag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already possible. Pass lookup in the connect option.

@hjr3
Copy link
Author

hjr3 commented Apr 19, 2024

For anyone else wading through the docs:

import * as dns from 'dns';


const agent = new Agent({
  connect: {
    lookup: dns.lookup,
  },
});

@hjr3 hjr3 closed this Apr 19, 2024
@hjr3 hjr3 deleted the dns-lookup branch April 19, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants