refactor: add time log
parent
8aec95ad34
commit
2a78765e6b
|
@ -6,13 +6,13 @@ const tunnelAgent = require('tunnel-agent')
|
||||||
const util = exports
|
const util = exports
|
||||||
const httpsAgent = new HttpsAgent({
|
const httpsAgent = new HttpsAgent({
|
||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
timeout: 15000,
|
timeout: 5000,
|
||||||
keepAliveTimeout: 60000, // free socket keepalive for 30 seconds
|
keepAliveTimeout: 60000, // free socket keepalive for 30 seconds
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
})
|
})
|
||||||
const httpAgent = new Agent({
|
const httpAgent = new Agent({
|
||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
timeout: 15000,
|
timeout: 5000,
|
||||||
keepAliveTimeout: 60000 // free socket keepalive for 30 seconds
|
keepAliveTimeout: 60000 // free socket keepalive for 30 seconds
|
||||||
})
|
})
|
||||||
let socketId = 0
|
let socketId = 0
|
||||||
|
|
|
@ -33,6 +33,7 @@ module.exports = function createConnectHandler (sslConnectInterceptor, fakeServe
|
||||||
function connect (req, cltSocket, head, hostname, port) {
|
function connect (req, cltSocket, head, hostname, port) {
|
||||||
// tunneling https
|
// tunneling https
|
||||||
// console.log('connect:', hostname, port)
|
// console.log('connect:', hostname, port)
|
||||||
|
const start = new Date().getTime()
|
||||||
try {
|
try {
|
||||||
const proxySocket = net.connect(port, hostname, () => {
|
const proxySocket = net.connect(port, hostname, () => {
|
||||||
cltSocket.write('HTTP/1.1 200 Connection Established\r\n' +
|
cltSocket.write('HTTP/1.1 200 Connection Established\r\n' +
|
||||||
|
@ -46,7 +47,8 @@ function connect (req, cltSocket, head, hostname, port) {
|
||||||
})
|
})
|
||||||
proxySocket.on('error', (e) => {
|
proxySocket.on('error', (e) => {
|
||||||
// 连接失败,可能被GFW拦截,或者服务端拥挤
|
// 连接失败,可能被GFW拦截,或者服务端拥挤
|
||||||
console.error('代理连接失败:', e.errno, hostname, port)
|
const end = new Date().getTime()
|
||||||
|
console.error('代理连接失败:', e.errno, hostname, port, (end - start) / 1000 + 'ms')
|
||||||
cltSocket.destroy()
|
cltSocket.destroy()
|
||||||
})
|
})
|
||||||
return proxySocket
|
return proxySocket
|
||||||
|
|
|
@ -73,12 +73,14 @@ module.exports = function createRequestHandler (requestInterceptor, responseInte
|
||||||
})
|
})
|
||||||
|
|
||||||
proxyReq.on('timeout', () => {
|
proxyReq.on('timeout', () => {
|
||||||
console.error('代理请求超时', rOptions.protocol, rOptions.hostname, rOptions.path)
|
const end = new Date().getTime()
|
||||||
|
console.error('代理请求超时', rOptions.protocol, rOptions.hostname, rOptions.path, (end - start) + 'ms')
|
||||||
reject(new Error(`${rOptions.host}:${rOptions.port}, 代理请求超时`))
|
reject(new Error(`${rOptions.host}:${rOptions.port}, 代理请求超时`))
|
||||||
})
|
})
|
||||||
|
|
||||||
proxyReq.on('error', (e, req, res) => {
|
proxyReq.on('error', (e, req, res) => {
|
||||||
console.error('代理请求错误', e.errno, rOptions.hostname, rOptions.path)
|
const end = new Date().getTime()
|
||||||
|
console.error('代理请求错误', e.errno, rOptions.hostname, rOptions.path, (end - start) + 'ms')
|
||||||
reject(e)
|
reject(e)
|
||||||
if (res) {
|
if (res) {
|
||||||
res.end()
|
res.end()
|
||||||
|
|
Loading…
Reference in New Issue