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