optimize self-signed certs

This commit is contained in:
加里
2014-08-22 17:00:20 +08:00
parent baf7f0e289
commit f438bed1e6
3 changed files with 10 additions and 7 deletions

View File

@@ -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){