From 3b712d6950f0b9c61d5377ecf0b2fee0a06eb3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Tue, 8 Oct 2024 17:54:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BC=98=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/proxy/mitmproxy/createRequestHandler.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js index 08974d6..094cb83 100644 --- a/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js +++ b/packages/mitmproxy/src/lib/proxy/mitmproxy/createRequestHandler.js @@ -1,6 +1,7 @@ const http = require('http') const https = require('https') const commonUtil = require('../common/util') +const jsonApi = require('../../../json') // const upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i const DnsUtil = require('../../dns/index') const log = require('../../../utils/util.log') @@ -105,7 +106,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e function onFree () { url = `${rOptions.method} ➜ ${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}` const start = new Date() - log.info('发起代理请求:', url, (rOptions.servername ? ', sni: ' + rOptions.servername : '')) + log.info('发起代理请求:', url, (rOptions.servername ? ', sni: ' + rOptions.servername : ''), ', headers:', rOptions.headers) const isDnsIntercept = {} if (dnsConfig && dnsConfig.providers) { @@ -149,7 +150,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e proxyReq.on('timeout', () => { const cost = new Date() - start const errorMsg = `代理请求超时: ${url}, cost: ${cost} ms` - log.error(errorMsg) + log.error(errorMsg, ', rOptions:', jsonApi.stringify2(rOptions)) countSlow(isDnsIntercept, `代理请求超时, cost: ${cost} ms`) proxyReq.end() proxyReq.destroy() @@ -159,14 +160,14 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e }) proxyReq.on('error', (e) => { const cost = new Date() - start - log.error(`代理请求错误: ${url}, cost: ${cost} ms, error:`, e) + log.error(`代理请求错误: ${url}, cost: ${cost} ms, error:`, e, ', rOptions:', jsonApi.stringify2(rOptions)) countSlow(isDnsIntercept, '代理请求错误: ' + e.message) reject(e) }) proxyReq.on('aborted', () => { const cost = new Date() - start const errorMsg = `代理请求被取消: ${url}, cost: ${cost} ms` - log.error(errorMsg) + log.error(errorMsg, ', rOptions:', jsonApi.stringify2(rOptions)) if (cost > MAX_SLOW_TIME) { countSlow(isDnsIntercept, `代理请求被取消,且请求太慢, cost: ${cost} ms > ${MAX_SLOW_TIME} ms`) @@ -182,7 +183,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e req.on('aborted', function () { const cost = new Date() - start const errorMsg = `请求被取消: ${url}, cost: ${cost} ms` - log.error(errorMsg) + log.error(errorMsg, ', rOptions:', jsonApi.stringify2(rOptions)) proxyReq.abort() if (res.writableEnded) { return @@ -191,13 +192,13 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e }) req.on('error', function (e, req, res) { const cost = new Date() - start - log.error(`请求错误: ${url}, cost: ${cost} ms, error:`, e) + log.error(`请求错误: ${url}, cost: ${cost} ms, error:`, e, ', rOptions:', jsonApi.stringify2(rOptions)) reject(e) }) req.on('timeout', () => { const cost = new Date() - start const errorMsg = `请求超时: ${url}, cost: ${cost} ms` - log.error(errorMsg) + log.error(errorMsg, ', rOptions:', jsonApi.stringify2(rOptions)) reject(new Error(errorMsg)) }) req.pipe(proxyReq)