mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
invoke log util, console.log can be switched off
This commit is contained in:
@@ -11,6 +11,7 @@ var http = require("http"),
|
||||
util = require("./util"),
|
||||
getPort = require("./getPort"),
|
||||
Stream = require("stream"),
|
||||
logUtil = require("./log"),
|
||||
httpsServerMgr = require("./httpsServerMgr");
|
||||
|
||||
var defaultRule = require("./rule_default.js"),
|
||||
@@ -40,7 +41,7 @@ function userRequestHandler(req,userRes){
|
||||
resourceInfoId = GLOBAL.recorder.appendRecord(resourceInfo);
|
||||
}
|
||||
|
||||
console.log(color.green("\nreceived request to : " + host + path));
|
||||
logUtil.printLog(color.green("\nreceived request to : " + host + path));
|
||||
|
||||
//get request body and route to local or remote
|
||||
async.series([fetchReqData,routeReq],function(){});
|
||||
@@ -63,10 +64,10 @@ function userRequestHandler(req,userRes){
|
||||
//route to dealing function
|
||||
function routeReq(callback){
|
||||
if(userRule.shouldUseLocalResponse(req,reqData)){
|
||||
console.log("==>use local rules");
|
||||
logUtil.printLog("==>use local rules");
|
||||
dealWithLocalResponse(callback);
|
||||
}else{
|
||||
console.log("==>will forward to real server by proxy");
|
||||
logUtil.printLog("==>will forward to real server by proxy");
|
||||
dealWithRemoteResonse(callback);
|
||||
}
|
||||
}
|
||||
@@ -163,7 +164,7 @@ function userRequestHandler(req,userRes){
|
||||
//get custom response
|
||||
},function(callback){
|
||||
if(userRule.replaceServerResData){
|
||||
console.log(color.red("replaceServerResData is deprecated, and will be unavilable soon. Use replaceServerResDataAsync instead."));
|
||||
logUtil.printLog(color.red("replaceServerResData is deprecated, and will be unavilable soon. Use replaceServerResDataAsync instead."), logUtil.T_ERR);
|
||||
serverResData = userRule.replaceServerResData(req,res,serverResData) || serverResData;
|
||||
callback();
|
||||
}else if(userRule.replaceServerResDataAsync){
|
||||
@@ -225,13 +226,13 @@ function userRequestHandler(req,userRes){
|
||||
|
||||
});
|
||||
res.on('error',function(error){
|
||||
console.log('error',error);
|
||||
logUtil.printLog('error' + error, logUtil.T_ERR);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
proxyReq.on("error",function(e){
|
||||
console.log("err with request :" + e + " " + req.url);
|
||||
logUtil.printLog("err with request :" + e + " " + req.url, logUtil.T_ERR);
|
||||
userRes.end();
|
||||
});
|
||||
|
||||
@@ -252,11 +253,11 @@ function connectReqHandler(req, socket, head){
|
||||
shouldIntercept = false; // TODO : a more general solution?
|
||||
}
|
||||
|
||||
console.log(color.green("\nreceived https CONNECT request " + host));
|
||||
logUtil.printLog(color.green("\nreceived https CONNECT request " + host));
|
||||
if(shouldIntercept){
|
||||
console.log("==>will forward to local https server");
|
||||
logUtil.printLog("==>will forward to local https server");
|
||||
}else{
|
||||
console.log("==>will bypass the man-in-the-middle proxy");
|
||||
logUtil.printLog("==>will bypass the man-in-the-middle proxy");
|
||||
}
|
||||
|
||||
//record
|
||||
@@ -334,10 +335,10 @@ function connectReqHandler(req, socket, head){
|
||||
});
|
||||
|
||||
conn.on("error",function(e){
|
||||
console.log("err when connect to %j, %j" , host , e);
|
||||
logUtil.printLog("err when connect to + " + host + " , " + e, logUtil.T_ERR);
|
||||
});
|
||||
}catch(e){
|
||||
console.log("err when connect to remote https server (__host)".replace(/__host/,host));
|
||||
logUtil.printLog("err when connect to remote https server (__host)".replace(/__host/,host), logUtil.T_ERR);
|
||||
}
|
||||
|
||||
//update record
|
||||
@@ -354,7 +355,7 @@ function connectReqHandler(req, socket, head){
|
||||
}
|
||||
],function(err,result){
|
||||
if(err){
|
||||
console.log("err " + err);
|
||||
logUtil.printLog("err " + err, logUtil.T_ERR);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
@@ -381,13 +382,13 @@ function setRules(newRule){
|
||||
}
|
||||
if('function' == typeof(userRule.summary)){
|
||||
functions.push(function(cb){
|
||||
console.log(userRule.summary());
|
||||
logUtil.printLog(userRule.summary());
|
||||
cb(null);
|
||||
});
|
||||
}
|
||||
async.series(functions,function(errors,result){
|
||||
if(!errors){
|
||||
console.log(color.green('Anyproxy rules initialize finished, have fun!'));
|
||||
logUtil.printLog(color.green('Anyproxy rules initialize finished, have fun!'));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user