优化sni拦截器

pull/284/head
王良 2024-03-26 15:06:26 +08:00
parent d513442c49
commit 8384b86d71
3 changed files with 9 additions and 2 deletions

View File

@ -64,7 +64,9 @@ module.exports = {
if (interceptOpt.sni != null) {
rOptions.servername = interceptOpt.sni
rOptions.agent.options.rejectUnauthorized = false
if (rOptions.agent) {
rOptions.agent.options.rejectUnauthorized = false
}
}
return true
},

View File

@ -3,6 +3,9 @@ module.exports = {
const { rOptions, log } = context
if (interceptOpt.sni != null) {
rOptions.servername = interceptOpt.sni
if (rOptions.agent) {
rOptions.agent.options.rejectUnauthorized = false
}
log.info('sni intercept: sni replace servername:', rOptions.hostname, '➜', rOptions.servername)
}
return true

View File

@ -40,7 +40,7 @@ util.getOptionsFromRequest = (req, ssl, externalProxy = null) => {
}
delete headers['proxy-connection']
let agent = false
let agent
if (!externalProxyUrl) {
// keepAlive
if (headers.connection !== 'close') {
@ -50,6 +50,8 @@ util.getOptionsFromRequest = (req, ssl, externalProxy = null) => {
agent = httpAgent
}
headers.connection = 'keep-alive'
} else {
agent = false
}
} else {
agent = util.getTunnelAgent(protocol === 'https:', externalProxyUrl)