Browse Source

重命名response拦截器为responseReplace,且响应头配置,支持 `[remove]` 值,来清除响应头。

pull/297/head
王良 7 months ago
parent
commit
1569026bc5
  1. 4
      packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js
  2. 4
      packages/mitmproxy/src/lib/interceptor/index.js

4
packages/mitmproxy/src/lib/interceptor/impl/res/response.js → packages/mitmproxy/src/lib/interceptor/impl/res/responseReplace.js

@ -24,7 +24,7 @@ function replaceHeaders (newHeaders, res, proxyRes) {
const newHeaderValue = newHeaders[headerKeyLower]
if (newHeaderValue && newHeaderValue !== proxyRes.rawHeaders[i + 1]) {
preHeaders[headerKeyLower] = proxyRes.rawHeaders[i + 1] // 先保存原先响应头
proxyRes.rawHeaders[i + 1] = newHeaderValue
proxyRes.rawHeaders[i + 1] = newHeaderValue === '[remove]' ? '' : newHeaderValue // 由于拦截配置中不允许配置null,会被删,所以配置一个[remove],当作删除响应头的意思
delete newHeaders[headerKeyLower]
}
}
@ -42,7 +42,7 @@ function replaceHeaders (newHeaders, res, proxyRes) {
}
module.exports = {
name: 'response',
name: 'responseReplace',
priority: 203,
replaceHeaders,
responseIntercept (context, interceptOpt, req, res, proxyReq, proxyRes, ssl, next) {

4
packages/mitmproxy/src/lib/interceptor/index.js

@ -13,7 +13,7 @@ const sni = require('./impl/req/sni')
// response interceptor impls
const cacheRes = require('./impl/res/cacheRes')
const script = require('./impl/res/script')
const response = require('./impl/res/response')
const responseReplace = require('./impl/res/responseReplace')
module.exports = [
// request interceptor impls
@ -23,5 +23,5 @@ module.exports = [
proxy, sni,
// response interceptor impls
cacheRes, script, response
cacheRes, script, responseReplace
]

Loading…
Cancel
Save