Skip to content

Commit

Permalink
兼容程序 修改为 自动兼容程序
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Oct 17, 2024
1 parent 09023f5 commit 6e88d43
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/gui/src/view/pages/server.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@
</a-col>
</a-row>
</a-tab-pane>
<a-tab-pane tab="兼容程序" key="5">
<a-tab-pane tab="自动兼容程序" key="5">
<div style="height:100%;display:flex;flex-direction:column">
<div>
说明:<code>兼容程序</code>会自动根据错误信息进行兼容性调整,并将兼容设置保存在 <code>~/.dev-sidecar/automaticCompatibleConfig.json</code> 文件中。但并不是所有的兼容设置都是正确的,所以需要通过以下配置来覆盖错误的兼容设置。
说明:<code>自动兼容程序</code>会自动根据错误信息进行兼容性调整,并将兼容设置保存在 <code>~/.dev-sidecar/automaticCompatibleConfig.json</code> 文件中。但并不是所有的兼容设置都是正确的,所以需要通过以下配置来覆盖错误的兼容设置。
</div>
<vue-json-editor style="flex-grow:1;min-height:300px;margin-top:10px;" ref="editor" v-model="config.server.compatible" mode="code"
:show-btns="false" :expandedOnStart="true"></vue-json-editor>
Expand Down
6 changes: 3 additions & 3 deletions packages/mitmproxy/src/lib/proxy/compatible/compatible.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* 兼容程序自适应生成配置
* 自动兼容程序自适应生成配置
* 此脚本会针对各种兼容性问题,为对应域名生成相应的兼容性配置,并将自适应配置写入到 `~/.dev-sidecar/automaticCompatibleConfig.json` 文件中。
* 当然,也有可能会生成错误的配置,导致无法兼容,这时候可以通过 `config.server.compatible` 配置项,来覆盖这里生成的配置,达到主动适配的效果。
*
Expand Down Expand Up @@ -110,7 +110,7 @@ module.exports = {
// 配置保存到文件
if (autoSave) _saveConfigToFile()

log.info(`【兼容程序${hostname}:${port}: 设置 connect.ssl = ${ssl}`)
log.info(`【自动兼容程序${hostname}:${port}: 设置 connect.ssl = ${ssl}`)
},

// --------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -140,6 +140,6 @@ module.exports = {
// 配置保存到文件
if (autoSave) _saveConfigToFile()

log.info(`【兼容程序${rOptions.hostname}:${rOptions.port}: 设置 request.rejectUnauthorized = ${rejectUnauthorized}`)
log.info(`【自动兼容程序${rOptions.hostname}:${rOptions.port}: 设置 request.rejectUnauthorized = ${rejectUnauthorized}`)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
// log.debug('agent.options:', rOptions.agent.options)
res.setHeader('DS-Proxy-Request', rOptions.hostname)

// 兼容程序:2
// 自动兼容程序:2
if (rOptions.agent) {
const compatibleConfig = compatible.getRequestCompatibleConfig(rOptions, rOptions.compatibleConfig)
if (compatibleConfig && compatibleConfig.rejectUnauthorized != null && rOptions.agent.options.rejectUnauthorized !== compatibleConfig.rejectUnauthorized) {
if (compatibleConfig.rejectUnauthorized === false && rOptions.agent.unVerifySslAgent) {
log.info(`【兼容程序${rOptions.hostname}:${rOptions.port}: 设置 'rOptions.agent.options.rejectUnauthorized = ${compatibleConfig.rejectUnauthorized}'`)
log.info(`【自动兼容程序${rOptions.hostname}:${rOptions.port}: 设置 'rOptions.agent.options.rejectUnauthorized = ${compatibleConfig.rejectUnauthorized}'`)
rOptions.agent = rOptions.agent.unVerifySslAgent
res.setHeader('DS-Compatible', 'unVerifySsl')
}
Expand Down Expand Up @@ -178,7 +178,7 @@ module.exports = function createRequestHandler (createIntercepts, middlewares, e
countSlow(isDnsIntercept, '代理请求错误: ' + e.message)
reject(e)

// 兼容程序:2
// 自动兼容程序:2
if (e.code === 'DEPTH_ZERO_SELF_SIGNED_CERT') {
compatible.setRequestRejectUnauthorized(rOptions, false)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/mitmproxy/src/lib/proxy/tls/FakeServersCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = class FakeServersCenter {
if (port === 443 || port === 80) {
ssl = port === 443
} else if (ssl) {
// 兼容程序:1
// 自动兼容程序:1
const compatibleConfig = compatible.getConnectCompatibleConfig(hostname, port, manualCompatibleConfig)
if (compatibleConfig && compatibleConfig.ssl != null) {
ssl = compatibleConfig.ssl
Expand Down Expand Up @@ -154,14 +154,14 @@ module.exports = class FakeServersCenter {
// log.error(`【fakeServer clientError - ${hostname}:${port}】\r\n----- error -----\r\n`, err, '\r\n----- socket -----\r\n', socket)
log.error(`【fakeServer clientError - ${hostname}:${port}】\r\n`, err)

// 兼容程序:1
// 自动兼容程序:1
if (port !== 443 && port !== 80) {
if (ssl === true && err.code.indexOf('ERR_SSL_') === 0) {
compatible.setConnectSsl(hostname, port, false)
log.error(`兼容程序:SSL异常,现设置为禁用ssl: ${hostname}:${port}, ssl = false`)
log.error(`自动兼容程序:SSL异常,现设置为禁用ssl: ${hostname}:${port}, ssl = false`)
} else if (ssl === false && err.code === 'HPE_INVALID_METHOD') {
compatible.setConnectSsl(hostname, port, true)
log.error(`兼容程序${err.code},现设置为启用ssl: ${hostname}:${port}, ssl = true`)
log.error(`自动兼容程序${err.code},现设置为启用ssl: ${hostname}:${port}, ssl = true`)
}
}
})
Expand Down

0 comments on commit 6e88d43

Please sign in to comment.