Skip to content

Commit

Permalink
重命名response拦截器为responseReplace,且响应头配置,支持 [remove] 值,来清除响应头。
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Apr 16, 2024
1 parent 21ddb20 commit 1569026
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/mitmproxy/src/lib/interceptor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,5 +23,5 @@ module.exports = [
proxy, sni,

// response interceptor impls
cacheRes, script, response
cacheRes, script, responseReplace
]

0 comments on commit 1569026

Please sign in to comment.