mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 04:01:27 +00:00
commit
70d0e39bac
@ -124,7 +124,7 @@ function Recorder(option){
|
||||
mime : "",
|
||||
content : ""
|
||||
};
|
||||
GLOBAL.recorder.getSingleRecord(id,function(err,doc){
|
||||
global.recorder.getSingleRecord(id,function(err,doc){
|
||||
//check whether this record exists
|
||||
if(!doc || !doc[0]){
|
||||
cb(new Error("failed to find record for this id"));
|
||||
|
@ -1,5 +1,5 @@
|
||||
var http = require("http"),
|
||||
https = require("https"),
|
||||
https = require("https"),
|
||||
net = require("net"),
|
||||
fs = require("fs"),
|
||||
url = require("url"),
|
||||
@ -46,8 +46,8 @@ function userRequestHandler(req,userRes){
|
||||
req : req,
|
||||
startTime : new Date().getTime()
|
||||
};
|
||||
if(GLOBAL.recorder){
|
||||
resourceInfoId = GLOBAL.recorder.appendRecord(resourceInfo);
|
||||
if(global.recorder){
|
||||
resourceInfoId = global.recorder.appendRecord(resourceInfo);
|
||||
}
|
||||
|
||||
logUtil.printLog(color.green("\nreceived request to : " + host + path));
|
||||
@ -59,7 +59,7 @@ function userRequestHandler(req,userRes){
|
||||
],function(){
|
||||
//mark some ext info
|
||||
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(){
|
||||
reqData = Buffer.concat(postData);
|
||||
resourceInfo.reqBody = reqData.toString();
|
||||
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||
global.recorder && global.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||
|
||||
callback();
|
||||
});
|
||||
@ -103,7 +103,7 @@ function userRequestHandler(req,userRes){
|
||||
resourceInfo.length = resBody ? resBody.length : 0;
|
||||
resourceInfo.statusCode = statusCode;
|
||||
|
||||
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||
global.recorder && global.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||
|
||||
userRes.writeHead(statusCode,resHeader);
|
||||
userRes.end(resBody);
|
||||
@ -212,10 +212,10 @@ function userRequestHandler(req,userRes){
|
||||
|
||||
//send response
|
||||
},function(callback){
|
||||
if(GLOBAL._throttle){
|
||||
if(global._throttle){
|
||||
var thrStream = new Stream();
|
||||
|
||||
var readable = thrStream.pipe(GLOBAL._throttle.throttle());
|
||||
var readable = thrStream.pipe(global._throttle.throttle());
|
||||
readable.pipe(userRes);
|
||||
|
||||
thrStream.emit("data",serverResData);
|
||||
@ -234,7 +234,7 @@ function userRequestHandler(req,userRes){
|
||||
resourceInfo.resBody = serverResData;
|
||||
resourceInfo.length = serverResData ? serverResData.length : 0;
|
||||
|
||||
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||
global.recorder && global.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||
|
||||
callback();
|
||||
|
||||
@ -294,7 +294,7 @@ function connectReqHandler(req, socket, head){
|
||||
req : req,
|
||||
startTime : new Date().getTime()
|
||||
};
|
||||
resourceInfoId = GLOBAL.recorder.appendRecord(resourceInfo);
|
||||
resourceInfoId = global.recorder.appendRecord(resourceInfo);
|
||||
|
||||
var proxyPort,
|
||||
proxyHost,
|
||||
@ -346,8 +346,8 @@ function connectReqHandler(req, socket, head){
|
||||
socket.write('HTTP/' + req.httpVersion + ' 200 OK\r\n\r\n', 'UTF-8', function(){
|
||||
|
||||
//throttle for direct-foward https
|
||||
if(GLOBAL._throttle && !shouldIntercept ){
|
||||
var readable = conn.pipe(GLOBAL._throttle.throttle());
|
||||
if(global._throttle && !shouldIntercept ){
|
||||
var readable = conn.pipe(global._throttle.throttle());
|
||||
readable.pipe(socket);
|
||||
socket.pipe(conn);
|
||||
}else{
|
||||
@ -374,7 +374,7 @@ function connectReqHandler(req, socket, head){
|
||||
resourceInfo.resBody = "";
|
||||
resourceInfo.length = 0;
|
||||
|
||||
GLOBAL.recorder && GLOBAL.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||
global.recorder && global.recorder.updateRecord(resourceInfoId,resourceInfo);
|
||||
|
||||
callback();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ function webInterface(config){
|
||||
app.get("/fetchBody",function(req,res){
|
||||
var query = req.query;
|
||||
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){
|
||||
res.json({});
|
||||
}else if(result.type && result.type == "image" && result.mime){
|
||||
|
@ -24,7 +24,7 @@ function resToMsg(msg,cb){
|
||||
|
||||
if(jsonData.type == "reqBody" && jsonData.id){
|
||||
result.type = "body";
|
||||
GLOBAL.recorder.getBody(jsonData.id, function(err, data){
|
||||
global.recorder.getBody(jsonData.id, function(err, data){
|
||||
if(err){
|
||||
result.content = {
|
||||
id : null,
|
||||
@ -74,7 +74,7 @@ function wsServer(config){
|
||||
|
||||
wss.on("close",function(){});
|
||||
|
||||
GLOBAL.recorder.on("update",function(data){
|
||||
global.recorder.on("update",function(data){
|
||||
try{
|
||||
wss && wss.broadcast({
|
||||
type : "update",
|
||||
|
@ -48,7 +48,6 @@
|
||||
"test": "sh test/test.sh",
|
||||
"testserver": "node test/server/startServer.js"
|
||||
},
|
||||
"optionalDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/alibaba/anyproxy"
|
||||
|
8
proxy.js
8
proxy.js
@ -1,5 +1,5 @@
|
||||
try{
|
||||
GLOBAL.util = require('./lib/util');
|
||||
global.util = require('./lib/util');
|
||||
}catch(e){}
|
||||
|
||||
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);
|
||||
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;
|
||||
@ -111,9 +111,9 @@ function proxyServer(option){
|
||||
function(callback){
|
||||
util.clearCacheDir(function(){
|
||||
if(option.dbFile){
|
||||
GLOBAL.recorder = new Recorder({filename: option.dbFile});
|
||||
global.recorder = new Recorder({filename: option.dbFile});
|
||||
}else{
|
||||
GLOBAL.recorder = new Recorder();
|
||||
global.recorder = new Recorder();
|
||||
}
|
||||
callback();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user