undici icon indicating copy to clipboard operation
undici copied to clipboard

The DNS Interceptor is unable to retrieve the origin properly

Open mehrab-hn opened this issue 8 months ago • 1 comments

Bug Description

In the code example below, I provide the URL twice: first, when creating the Client instance, and again as the origin in the request options. This redundancy is unnecessary. However, when using the DNS interceptor, omitting the URL from the request options will result in an error.

Reproducible By

import { Client, interceptors } from 'undici';
const { dns } = interceptors;

const client = new Client('https://jsonplaceholder.typicode.com/').compose(dns());

const response = await client.request({
  origin: 'https://jsonplaceholder.typicode.com/', // Commenting this line will cause an error
  method: 'GET',
  path: '/posts/1',
  headers: {
    'Content-Type': 'application/json',
  },
});

const data = await response.body.json();
console.log(data);

Expected Behavior

The DNS interceptor should be capable of retrieving the URL directly from the client.

Logs & Screenshots

Image

Environment

Ubuntu 22.04 LTS, Node v22.15.1, npm v10.9.2 undici v7.10.0

mehrab-hn avatar May 21 '25 19:05 mehrab-hn

See discussions here: #3957

Basically origin must be provided each time with Client (and Pool).

luddd3 avatar May 23 '25 14:05 luddd3