2014-09-01 16:38:43 +08:00
|
|
|
//rule scheme :
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
2014-10-21 11:18:55 +08:00
|
|
|
replaceServerResDataAsync: function(req,res,serverResData,callback){
|
2014-09-01 16:38:43 +08:00
|
|
|
//append "hello world" to all web pages
|
2015-05-20 16:32:25 +08:00
|
|
|
|
|
|
|
//for those non-unicode response , serverResData.toString() should not be your first choice.
|
|
|
|
//this issue may help you understanding how to modify an non-unicode response: https://github.com/alibaba/anyproxy/issues/20
|
2014-09-01 16:38:43 +08:00
|
|
|
if(/html/i.test(res.headers['content-type'])){
|
|
|
|
var newDataStr = serverResData.toString();
|
|
|
|
newDataStr += "hello world!";
|
2014-10-21 11:18:55 +08:00
|
|
|
callback(newDataStr);
|
2014-09-01 16:38:43 +08:00
|
|
|
}else{
|
2014-10-21 11:18:55 +08:00
|
|
|
callback(serverResData);
|
2014-09-01 16:38:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-03-08 12:00:39 +08:00
|
|
|
};
|