anyproxy/rule_sample/rule_replace_response_data.js

20 lines
651 B
JavaScript
Raw Normal View History

//rule scheme :
module.exports = {
2014-10-21 11:18:55 +08:00
replaceServerResDataAsync: function(req,res,serverResData,callback){
//append "hello world" to all web pages
//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
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);
}else{
2014-10-21 11:18:55 +08:00
callback(serverResData);
}
}
};