diff --git a/lib/recorder.js b/lib/recorder.js index 06100b377..991716342 100644 --- a/lib/recorder.js +++ b/lib/recorder.js @@ -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")); @@ -230,4 +230,4 @@ function normalizeInfo(id,info){ return singleRecord; } -module.exports = Recorder; \ No newline at end of file +module.exports = Recorder; diff --git a/lib/requestHandler.js b/lib/requestHandler.js index 2f79d836f..f0f9a7eae 100644 --- a/lib/requestHandler.js +++ b/lib/requestHandler.js @@ -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(); } diff --git a/lib/webInterface.js b/lib/webInterface.js index 3e745974e..cc616ea16 100644 --- a/lib/webInterface.js +++ b/lib/webInterface.js @@ -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){ @@ -154,4 +154,4 @@ function webInterface(config){ inherits(webInterface, events.EventEmitter); -module.exports = webInterface; \ No newline at end of file +module.exports = webInterface; diff --git a/lib/wsServer.js b/lib/wsServer.js index d56fb4afa..81da63a3b 100644 --- a/lib/wsServer.js +++ b/lib/wsServer.js @@ -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", @@ -95,4 +95,4 @@ wsServer.prototype.closeAll = function(){ self.wss.close(); } -module.exports = wsServer; \ No newline at end of file +module.exports = wsServer; diff --git a/package.json b/package.json index d58f7361b..20e018129 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/proxy.js b/proxy.js index 85b941181..8f566d7f7 100644 --- a/proxy.js +++ b/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(); });