mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
optimze map icon
This commit is contained in:
@@ -15,7 +15,6 @@ function Recorder(option){
|
||||
|
||||
option = option || {};
|
||||
if(option.filename && typeof option.filename == "string"){
|
||||
|
||||
try{
|
||||
if(fs.existsSync(option.filename)){
|
||||
fs.writeFileSync(option.filename,""); //empty original file
|
||||
@@ -39,9 +38,20 @@ function Recorder(option){
|
||||
db = new Datastore();
|
||||
}
|
||||
|
||||
|
||||
self.recordBodyMap = []; // id - body
|
||||
|
||||
self.emitUpdate = function(id,info){
|
||||
if(info){
|
||||
self.emit("update",info);
|
||||
}else{
|
||||
self.getSingleRecord(id,function(err,doc){
|
||||
if(!err && !!doc && !!doc[0]){
|
||||
self.emit("update",doc[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
self.updateRecord = function(id,info){
|
||||
if(id < 0 ) return;
|
||||
|
||||
@@ -50,10 +60,18 @@ function Recorder(option){
|
||||
db.update({_id:id},finalInfo);
|
||||
self.updateRecordBody(id,info);
|
||||
|
||||
self.emit("update",finalInfo);
|
||||
self.emitUpdate(id,finalInfo);
|
||||
};
|
||||
|
||||
|
||||
self.updateExtInfo = function(id,extInfo){
|
||||
db.update({_id:id},{ $set: { ext: extInfo } },{},function(err,nums){
|
||||
if(!err){
|
||||
self.emitUpdate(id);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
self.appendRecord = function(info){
|
||||
if(info.req.headers.anyproxy_web_req){ //request from web interface
|
||||
return -1;
|
||||
@@ -64,10 +82,9 @@ function Recorder(option){
|
||||
db.insert(finalInfo);
|
||||
self.updateRecordBody(id,info);
|
||||
|
||||
self.emit("update",finalInfo);
|
||||
self.emitUpdate(id,finalInfo);
|
||||
return thisId;
|
||||
};
|
||||
|
||||
|
||||
//update recordBody if exits
|
||||
self.updateRecordBody =function(id,info){
|
||||
@@ -91,9 +108,7 @@ function Recorder(option){
|
||||
return self.recordBodyMap[id] || "";
|
||||
};
|
||||
|
||||
|
||||
self.getBodyUTF8 = function(id,cb){
|
||||
|
||||
var bodyContent = self.getBody(id),
|
||||
result = "";
|
||||
|
||||
@@ -123,17 +138,16 @@ function Recorder(option){
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
self.getSingleRecord = function(id,cb){
|
||||
db.find({_id:parseInt(id)},cb);
|
||||
}
|
||||
};
|
||||
|
||||
self.getSummaryList = function(cb){
|
||||
db.find({},cb);
|
||||
};
|
||||
|
||||
|
||||
self.db = db;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,15 @@ function userRequestHandler(req,userRes){
|
||||
logUtil.printLog(color.green("\nreceived request to : " + host + path));
|
||||
|
||||
//get request body and route to local or remote
|
||||
async.series([fetchReqData,routeReq],function(){});
|
||||
async.series([
|
||||
fetchReqData,
|
||||
routeReq
|
||||
],function(){
|
||||
//mark some ext info
|
||||
if(req.anyproxy_map_local){
|
||||
GLOBAL.recorder.updateExtInfo(resourceInfoId, {map : req.anyproxy_map_local});
|
||||
}
|
||||
});
|
||||
|
||||
//get request body
|
||||
function fetchReqData(callback){
|
||||
@@ -408,5 +416,5 @@ module.exports.getRuleSummary = getRuleSummary;
|
||||
note
|
||||
req.url is wired
|
||||
in http server : http://www.example.com/a/b/c
|
||||
in https server : /work/alibaba
|
||||
in https server : /a/b/c
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,7 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return !!req.anyproxy_map_local;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user