mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-08-04 21:39:04 +00:00
code backup
This commit is contained in:
@@ -4,6 +4,7 @@ var zlib = require('zlib'),
|
||||
util = require("util"),
|
||||
fs = require("fs"),
|
||||
events = require('events'),
|
||||
iconv = require('iconv-lite'),
|
||||
logUtil = require("./log");
|
||||
|
||||
//option.filename
|
||||
@@ -82,8 +83,6 @@ function Recorder(option){
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
self.getBody = function(id){
|
||||
if(id < 0){
|
||||
return "";
|
||||
@@ -92,6 +91,39 @@ function Recorder(option){
|
||||
return self.recordBodyMap[id] || "";
|
||||
};
|
||||
|
||||
|
||||
self.getBodyUTF8 = function(id,cb){
|
||||
|
||||
var bodyContent = self.getBody(id),
|
||||
result = "";
|
||||
|
||||
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"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!bodyContent){
|
||||
cb(null,result);
|
||||
}
|
||||
|
||||
var record = doc[0],
|
||||
resHeader = record['resHeader'] || {};
|
||||
try{
|
||||
var charsetMatch = JSON.stringify(resHeader).match(/charset="?([a-zA-Z0-9\-]+)"?/);
|
||||
if(charsetMatch && charsetMatch.length > 1){
|
||||
var currentCharset = charsetMatch[1].toLowerCase();
|
||||
if(currentCharset != "utf-8" && iconv.encodingExists(currentCharset)){
|
||||
bodyContent = iconv.decode(bodyContent, currentCharset);
|
||||
}
|
||||
}
|
||||
}catch(e){}
|
||||
|
||||
cb(null,bodyContent.toString());
|
||||
});
|
||||
}
|
||||
|
||||
self.getSingleRecord = function(id,cb){
|
||||
db.find({_id:parseInt(id)},cb);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user