@wiajs/agent
Advanced tools
Comparing version 1.0.18 to 1.0.19
@@ -11,3 +11,3 @@ import * as dns from 'node:dns'; | ||
}); | ||
/** @typedef {import('stream').Duplex} Duplex */ /** @typedef {{protocol?: string, keepAlive: boolean} & import('net').TcpNetConnectOpts} HttpConnectOpts */ /** @typedef {{servername?:string, protocol?: string, port: number, keepAlive: boolean} & import('tls').ConnectionOptions} HttpsConnectOpts */ /** @typedef {HttpConnectOpts | HttpsConnectOpts} AgentConnectOpts */ /** @typedef {{protocol: string, host: string, port: number, type?: number, username?: string, userId?: string, password?: string}} Proxy */ /** | ||
/** @typedef {import('stream').Duplex} Duplex */ /** @typedef {{protocol?: string, keepAlive: boolean, lookup: dns.lookup} & import('net').TcpNetConnectOpts} HttpConnectOpts */ /** @typedef {{servername?:string, protocol?: string, port: number, keepAlive: boolean, lookup: dns.lookup} & import('tls').ConnectionOptions} HttpsConnectOpts */ /** @typedef {HttpConnectOpts | HttpsConnectOpts} AgentConnectOpts */ /** @typedef {{protocol: string, host: string, port: number, type?: number, username?: string, userId?: string, password?: string}} Proxy */ /** | ||
* 通过 http[s] 创建隧道代理连接 | ||
@@ -101,8 +101,31 @@ * @param {AgentConnectOpts} opts | ||
/** | ||
* 解析域名为ip地址 | ||
* @param {string} host | ||
* @param {dns.lookup} lookupFn | ||
* @returns {Promise<string>} | ||
*/ async function lookup(host, lookupFn) { | ||
let R; | ||
try { | ||
R = new Promise((res, rej)=>{ | ||
// Use the request's custom lookup, if one was configured: | ||
lookupFn(host, {}, (err, addr, family)=>{ | ||
if (err) rej(err); | ||
else res(addr); | ||
}); | ||
}); | ||
log({ | ||
R | ||
}, 'lookup'); | ||
} catch (e) { | ||
log.err(e, 'lookup'); | ||
} | ||
return R; | ||
} | ||
/** | ||
* 通过 socks 创建隧道代理连接 | ||
* @param {AgentConnectOpts} opts | ||
* @param {Proxy} proxy | ||
* @param {boolean} [lookup=false] | ||
* @param {boolean} [shouldLookup=false] | ||
* @returns {Promise<net.Socket | tls.TLSSocket>} | ||
*/ async function socksConnect(opts, proxy, lookup = false) { | ||
*/ async function socksConnect(opts, proxy, shouldLookup = false) { | ||
let R; | ||
@@ -112,16 +135,8 @@ try { | ||
let { host, port } = opts; | ||
if (!host) throw new Error('No `host` defined!'); | ||
port = typeof port === 'number' ? port : Number.parseInt(port); | ||
const { lookup: lookupFn = dns.lookup } = opts; | ||
if (lookup) { | ||
if (shouldLookup) { | ||
// Client-side DNS resolution for "4" and "5" socks proxy versions. | ||
host = await new Promise((resolve, reject)=>{ | ||
// Use the request's custom lookup, if one was configured: | ||
lookupFn(host, {}, (err, res)=>{ | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(res); | ||
} | ||
}); | ||
}); | ||
host = await lookup(host, lookupFn); | ||
} | ||
@@ -128,0 +143,0 @@ // Using socks library to create SOCKS connection |
{ | ||
"name": "@wiajs/agent", | ||
"description": "http/https/socks/tunnel/transfer's proxy agent", | ||
"version": "1.0.18", | ||
"version": "1.0.19", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"types": "types/index.d.ts", | ||
"exports": { | ||
@@ -56,3 +56,3 @@ ".": { | ||
"dependencies": { | ||
"@wiajs/log": "^4.3.16", | ||
"@wiajs/log": "^4.3.18", | ||
"socks": "^2.8.3" | ||
@@ -59,0 +59,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65852
15
1505
Updated@wiajs/log@^4.3.18