Skip to content

Commit

Permalink
optimize: script拦截器,只拦截 'text/html' 响应
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Sep 12, 2024
1 parent 8dba191 commit 9fe8e84
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/mitmproxy/src/lib/interceptor/impl/res/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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'
}
Expand Down

0 comments on commit 9fe8e84

Please sign in to comment.