add some tip in rules about non-unicode response

This commit is contained in:
OttoMao 2015-05-20 16:32:25 +08:00
parent e98295379b
commit 66b3b86a12
2 changed files with 4 additions and 1 deletions

View File

@ -98,7 +98,7 @@ module.exports = {
//替换服务器响应的数据
//replace the response from the server before it's sent to the user
//you may return either a Buffer or a string
//serverResData is a Buffer, you may get its content by calling serverResData.toString()
//serverResData is a Buffer. for those non-unicode reponse , serverResData.toString() should not be your first choice.
replaceServerResDataAsync: function(req,res,serverResData,callback){
callback(serverResData);
},

View File

@ -4,6 +4,9 @@ module.exports = {
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!";