-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 新增支持 MITM 配置,支持部分的启用 https 拦截以改善 w2 代理性能
- Loading branch information
Showing
7 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as server } from './server'; | ||
export { rulesServer } from './rulesServer'; | ||
export { tunnelRulesServer } from './tunnelRulesServer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
export default (server: Whistle.PluginServer, options: Whistle.PluginOptions) => { | ||
import { getConfig } from './lib/getConfig'; | ||
import { rulesManage } from './lib/rulesManage'; | ||
|
||
function mitmMatch(req: Whistle.PluginRequest) { | ||
if (rulesManage.rules['res-body'].size === 0) return; | ||
|
||
const host = (req.headers.host || new URL(req.originalReq.fullUrl).host).split(':')[0]; | ||
const resBodyRules = rulesManage.rules['res-body'].values(); | ||
|
||
for (const item of resBodyRules) { | ||
if (item.mitm) { | ||
const isMatch = (item.mitm as (string | RegExp)[]).some(d => (d instanceof RegExp ? d.test(host) : d === host)); | ||
if (isMatch) return host; | ||
} | ||
} | ||
} | ||
|
||
export function tunnelRulesServer(server: Whistle.PluginServer, _options: Whistle.PluginOptions) { | ||
server.on('request', (req: Whistle.PluginRequest, res: Whistle.PluginResponse) => { | ||
res.end(); | ||
const { isSNI, enableCapture } = req.originalReq; | ||
if (enableCapture || !isSNI || getConfig().enableMITM === false) return res.end(); | ||
|
||
const host = mitmMatch(req); | ||
host ? res.end(`${host} enable://intercept`) : res.end(); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters