1import { Agent, fetch } from 'undici';234const agent = new Agent({5 connect: {6 7 lookupTimeout: 1000,8 9 10 11 12 13 lookupAlgorithm: 'ipv4first',14 15 16 family: 0,17 18 19 lookup: (hostname, options, callback) => {20 console.log(`Custom DNS lookup for: ${hostname}`);21 22 23 const dns = require('dns');24 dns.lookup(hostname, options, callback);25 }26 },27 28 29 connectTimeout: 5000,30 31 32 connections: 1033});3435async function makeRequest() {36 console.log('Making request with custom DNS resolution...');37 38 try {39 40 const response = await fetch('https://example.com', { 41 dispatcher: agent 42 });43 44 const text = await response.text();45 console.log(`Response status: ${response.status}`);46 console.log(`Response size: ${text.length} bytes`);47 console.log(`First 100 characters: ${text.substring(0, 100)}...`);48 49 50 console.log('\nConnection Information:');51 console.log(`Protocol: ${response.headers.get('x-forwarded-proto') || 'https'}`);52 console.log(`Server: ${response.headers.get('server')}`);53 54 } catch (error) {55 console.error('Request failed:', error);56 } finally {57 58 await agent.close();59 }60}616263makeRequest();