fix: 修复ipv6未开启情况下,请求带有ipv6地址域名报ETIMEDOUT的bug

pull/243/head
xiaojunnuo 2024-11-12 11:14:48 +08:00
parent 7bbaa3806b
commit a9a0967a6f
2 changed files with 8 additions and 20 deletions

View File

@ -207,6 +207,14 @@ export type CreateAgentOptions = {
httpsProxy?: string; httpsProxy?: string;
} & nodeHttp.AgentOptions; } & nodeHttp.AgentOptions;
export function createAgent(opts: CreateAgentOptions = {}) { export function createAgent(opts: CreateAgentOptions = {}) {
opts = merge(
{
autoSelectFamily: true,
autoSelectFamilyAttemptTimeout: 2000,
},
opts
);
let httpAgent, httpsAgent; let httpAgent, httpsAgent;
const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy; const httpProxy = opts.httpProxy || process.env.HTTP_PROXY || process.env.http_proxy;
if (httpProxy) { if (httpProxy) {

20
test.js
View File

@ -1,20 +0,0 @@
import axios from 'axios'
import dns from "dns";
// axios.request({
// url:"http://[2407:3740:0:301::c]/"
// }).then(res=>{
// console.log(res)
// })
//
// dns.resolve("api.cloudflare.com", (err, address) => {
// console.log(address);
// })
import {http} from '@certd/basic'
http.request({
url:"https://api.cloudflare.com"
}).then(res=>{
console.log(res)
})