mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-07-27 07:45:41 +00:00
optimize self-signed certs
This commit is contained in:
@@ -20,7 +20,7 @@ var handleRule = {
|
||||
// }
|
||||
]
|
||||
,httpsConfig:{
|
||||
bypassAll : false,
|
||||
bypassAll : true,
|
||||
interceptDomains:["^.*alibaba-inc\.com$"]
|
||||
}
|
||||
};
|
||||
@@ -51,6 +51,7 @@ function userRequestHandler(req,userRes){
|
||||
var hostTest = new RegExp(rule.host).test(host),
|
||||
pathTest = new RegExp(rule.path).test(path);
|
||||
|
||||
//TODO : CORS for local file
|
||||
if(hostTest && pathTest && (rule.localFile || rule.localDir) ){
|
||||
console.log("==>meet the rules, will map to local file");
|
||||
|
||||
@@ -112,12 +113,13 @@ function connectReqHandler(req, socket, head){
|
||||
targetPort= req.url.split(":")[1],
|
||||
httpsRule = handleRule.httpsConfig;
|
||||
|
||||
var shouldBypass = httpsRule.bypassAll;
|
||||
var shouldBypass = !!httpsRule.bypassAll;
|
||||
if(!shouldBypass){ //read rules
|
||||
shouldBypass = true;
|
||||
for(var index in httpsRule.interceptDomains){
|
||||
var reg = new RegExp(httpsRule.interceptDomains[index]);
|
||||
if( reg.test(hostname) ){
|
||||
shouldBypass = true;
|
||||
shouldBypass = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -126,7 +128,7 @@ function connectReqHandler(req, socket, head){
|
||||
console.log(color.green("\nreceived https CONNECT request " + hostname));
|
||||
|
||||
if(shouldBypass){
|
||||
console.log("==>meet the rules, will bypass the man-in-the-middle proxy");
|
||||
console.log("==>will bypass the man-in-the-middle proxy");
|
||||
try{
|
||||
var conn = net.connect(targetPort, hostname, function(){
|
||||
socket.write('HTTP/' + req.httpVersion + ' 200 OK\r\n\r\n', 'UTF-8', function() {
|
||||
@@ -144,7 +146,7 @@ function connectReqHandler(req, socket, head){
|
||||
|
||||
}else{
|
||||
//TODO : remote port other than 433
|
||||
console.log("==>will forward to local https server");
|
||||
console.log("==>meet the rules, will forward to local https server");
|
||||
|
||||
//forward the https-request to local https server
|
||||
httpsServerMgrInstance.fetchPort(hostname,userRequestHandler,function(err,port){
|
||||
|
Reference in New Issue
Block a user