From 9fe8e84fea6dfd94ee7475360e0928e324ca2286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Thu, 12 Sep 2024 15:30:21 +0800 Subject: [PATCH] =?UTF-8?q?optimize:=20script=E6=8B=A6=E6=88=AA=E5=99=A8?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E6=8B=A6=E6=88=AA=20'text/html'=20=E5=93=8D?= =?UTF-8?q?=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mitmproxy/src/lib/interceptor/impl/res/script.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/mitmproxy/src/lib/interceptor/impl/res/script.js b/packages/mitmproxy/src/lib/interceptor/impl/res/script.js index d31f57f26c..f5f974a794 100644 --- a/packages/mitmproxy/src/lib/interceptor/impl/res/script.js +++ b/packages/mitmproxy/src/lib/interceptor/impl/res/script.js @@ -28,6 +28,12 @@ module.exports = { return } + // 如果没有响应头 'content-type',或其值不是 'text/html',则不处理 + if (!proxyRes.headers['content-type'] || proxyRes.headers['content-type'].indexOf('text/html') < 0) { + res.setHeader('DS-Script-Interceptor', 'Not text/html') + return + } + let keys = interceptOpt.script if (typeof keys === 'string') { keys = [keys] @@ -70,7 +76,7 @@ module.exports = { } res.setHeader('DS-Script-Interceptor', 'true') - log.info('script response intercept: insert script', rOptions.hostname, rOptions.path, ', head:', tags) + log.info(`script response intercept: insert script ${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}${rOptions.path}`, ', head:', tags) return { head: tags + '\r\n' }