mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-23 20:31:25 +00:00
change: discard decrpecated GLOBAL
This commit is contained in:
parent
207a20adf2
commit
4144beecc1
@ -124,7 +124,7 @@ function Recorder(option){
|
|||||||
mime : "",
|
mime : "",
|
||||||
content : ""
|
content : ""
|
||||||
};
|
};
|
||||||
GLOBAL.recorder.getSingleRecord(id,function(err,doc){
|
global.recorder.getSingleRecord(id,function(err,doc){
|
||||||
//check whether this record exists
|
//check whether this record exists
|
||||||
if(!doc || !doc[0]){
|
if(!doc || !doc[0]){
|
||||||
cb(new Error("failed to find record for this id"));
|
cb(new Error("failed to find record for this id"));
|
||||||
|
@ -46,8 +46,8 @@ function userRequestHandler(req,userRes){
|
|||||||
req : req,
|
req : req,
|
||||||
startTime : new Date().getTime()
|
startTime : new Date().getTime()
|
||||||
};
|
};
|
||||||
if(GLOBAL.recorder){
|
if(global.recorder){
|
||||||
resourceInfoId = GLOBAL.recorder.appendRecord(resourceInfo);
|
resourceInfoId = global.recorder.appendRecord(resourceInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
logUtil.printLog(color.green("\nreceived request to : " + host + path));
|
logUtil.printLog(color.green("\nreceived request to : " + host + path));
|
||||||
@ -59,7 +59,7 @@ function userRequestHandler(req,userRes){
|
|||||||
],function(){
|
],function(){
|
||||||
//mark some ext info
|
//mark some ext info
|
||||||
if(req.anyproxy_map_local){
|
if(req.anyproxy_map_local){
|
||||||
GLOBAL.recorder.updateExtInfo(resourceInfoId, {map : req.anyproxy_map_local});
|
global.recorder.updateExtInfo(resourceInfoId, {map : req.anyproxy_map_local});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ function userRequestHandler(req,userRes){
|
|||||||
req.on("end",function(){
|
req.on("end",function(){
|
||||||
reqData = Buffer.concat(postData);
|
reqData = Buffer.concat(postData);
|
||||||
resourceInfo.reqBody = reqData.toString();
|
resourceInfo.reqBody = reqData.toString();
|
||||||
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
global.recorder && global.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
@ -103,7 +103,7 @@ function userRequestHandler(req,userRes){
|
|||||||
resourceInfo.length = resBody ? resBody.length : 0;
|
resourceInfo.length = resBody ? resBody.length : 0;
|
||||||
resourceInfo.statusCode = statusCode;
|
resourceInfo.statusCode = statusCode;
|
||||||
|
|
||||||
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
global.recorder && global.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||||
|
|
||||||
userRes.writeHead(statusCode,resHeader);
|
userRes.writeHead(statusCode,resHeader);
|
||||||
userRes.end(resBody);
|
userRes.end(resBody);
|
||||||
@ -212,10 +212,10 @@ function userRequestHandler(req,userRes){
|
|||||||
|
|
||||||
//send response
|
//send response
|
||||||
},function(callback){
|
},function(callback){
|
||||||
if(GLOBAL._throttle){
|
if(global._throttle){
|
||||||
var thrStream = new Stream();
|
var thrStream = new Stream();
|
||||||
|
|
||||||
var readable = thrStream.pipe(GLOBAL._throttle.throttle());
|
var readable = thrStream.pipe(global._throttle.throttle());
|
||||||
readable.pipe(userRes);
|
readable.pipe(userRes);
|
||||||
|
|
||||||
thrStream.emit("data",serverResData);
|
thrStream.emit("data",serverResData);
|
||||||
@ -233,8 +233,13 @@ function userRequestHandler(req,userRes){
|
|||||||
resourceInfo.resHeader = resHeader;
|
resourceInfo.resHeader = resHeader;
|
||||||
resourceInfo.resBody = serverResData;
|
resourceInfo.resBody = serverResData;
|
||||||
resourceInfo.length = serverResData ? serverResData.length : 0;
|
resourceInfo.length = serverResData ? serverResData.length : 0;
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||||
|
=======
|
||||||
|
|
||||||
|
global.recorder && global.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||||
|
>>>>>>> 6521604... change: discard decrpecated GLOBAL
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
|
||||||
@ -294,7 +299,7 @@ function connectReqHandler(req, socket, head){
|
|||||||
req : req,
|
req : req,
|
||||||
startTime : new Date().getTime()
|
startTime : new Date().getTime()
|
||||||
};
|
};
|
||||||
resourceInfoId = GLOBAL.recorder.appendRecord(resourceInfo);
|
resourceInfoId = global.recorder.appendRecord(resourceInfo);
|
||||||
|
|
||||||
var proxyPort,
|
var proxyPort,
|
||||||
proxyHost,
|
proxyHost,
|
||||||
@ -346,8 +351,8 @@ function connectReqHandler(req, socket, head){
|
|||||||
socket.write('HTTP/' + req.httpVersion + ' 200 OK\r\n\r\n', 'UTF-8', function(){
|
socket.write('HTTP/' + req.httpVersion + ' 200 OK\r\n\r\n', 'UTF-8', function(){
|
||||||
|
|
||||||
//throttle for direct-foward https
|
//throttle for direct-foward https
|
||||||
if(GLOBAL._throttle && !shouldIntercept ){
|
if(global._throttle && !shouldIntercept ){
|
||||||
var readable = conn.pipe(GLOBAL._throttle.throttle());
|
var readable = conn.pipe(global._throttle.throttle());
|
||||||
readable.pipe(socket);
|
readable.pipe(socket);
|
||||||
socket.pipe(conn);
|
socket.pipe(conn);
|
||||||
}else{
|
}else{
|
||||||
@ -373,8 +378,13 @@ function connectReqHandler(req, socket, head){
|
|||||||
resourceInfo.resHeader = {};
|
resourceInfo.resHeader = {};
|
||||||
resourceInfo.resBody = "";
|
resourceInfo.resBody = "";
|
||||||
resourceInfo.length = 0;
|
resourceInfo.length = 0;
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||||
|
=======
|
||||||
|
|
||||||
|
global.recorder && global.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||||
|
>>>>>>> 6521604... change: discard decrpecated GLOBAL
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ function webInterface(config){
|
|||||||
app.get("/fetchBody",function(req,res){
|
app.get("/fetchBody",function(req,res){
|
||||||
var query = req.query;
|
var query = req.query;
|
||||||
if(query && query.id){
|
if(query && query.id){
|
||||||
GLOBAL.recorder.getDecodedBody(query.id, function(err, result){
|
global.recorder.getDecodedBody(query.id, function(err, result){
|
||||||
if(err || !result || !result.content){
|
if(err || !result || !result.content){
|
||||||
res.json({});
|
res.json({});
|
||||||
}else if(result.type && result.type == "image" && result.mime){
|
}else if(result.type && result.type == "image" && result.mime){
|
||||||
|
@ -24,7 +24,7 @@ function resToMsg(msg,cb){
|
|||||||
|
|
||||||
if(jsonData.type == "reqBody" && jsonData.id){
|
if(jsonData.type == "reqBody" && jsonData.id){
|
||||||
result.type = "body";
|
result.type = "body";
|
||||||
GLOBAL.recorder.getBody(jsonData.id, function(err, data){
|
global.recorder.getBody(jsonData.id, function(err, data){
|
||||||
if(err){
|
if(err){
|
||||||
result.content = {
|
result.content = {
|
||||||
id : null,
|
id : null,
|
||||||
@ -74,7 +74,7 @@ function wsServer(config){
|
|||||||
|
|
||||||
wss.on("close",function(){});
|
wss.on("close",function(){});
|
||||||
|
|
||||||
GLOBAL.recorder.on("update",function(data){
|
global.recorder.on("update",function(data){
|
||||||
try{
|
try{
|
||||||
wss && wss.broadcast({
|
wss && wss.broadcast({
|
||||||
type : "update",
|
type : "update",
|
||||||
|
8
proxy.js
8
proxy.js
@ -1,5 +1,5 @@
|
|||||||
try{
|
try{
|
||||||
GLOBAL.util = require('./lib/util');
|
global.util = require('./lib/util');
|
||||||
}catch(e){}
|
}catch(e){}
|
||||||
|
|
||||||
var http = require('http'),
|
var http = require('http'),
|
||||||
@ -100,7 +100,7 @@ function proxyServer(option){
|
|||||||
logUtil.printLog(color.red('Invalid throttle rate value, should be positive integer\n'), logUtil.T_ERR);
|
logUtil.printLog(color.red('Invalid throttle rate value, should be positive integer\n'), logUtil.T_ERR);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
GLOBAL._throttle = new ThrottleGroup({rate: 1024 * parseFloat(option.throttle) }); // rate - byte/sec
|
global._throttle = new ThrottleGroup({rate: 1024 * parseFloat(option.throttle) }); // rate - byte/sec
|
||||||
}
|
}
|
||||||
|
|
||||||
self.httpProxyServer = null;
|
self.httpProxyServer = null;
|
||||||
@ -111,9 +111,9 @@ function proxyServer(option){
|
|||||||
function(callback){
|
function(callback){
|
||||||
util.clearCacheDir(function(){
|
util.clearCacheDir(function(){
|
||||||
if(option.dbFile){
|
if(option.dbFile){
|
||||||
GLOBAL.recorder = new Recorder({filename: option.dbFile});
|
global.recorder = new Recorder({filename: option.dbFile});
|
||||||
}else{
|
}else{
|
||||||
GLOBAL.recorder = new Recorder();
|
global.recorder = new Recorder();
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user