From 66b3b86a1263e7feccc824b7319109c8f1aa691d Mon Sep 17 00:00:00 2001 From: OttoMao Date: Wed, 20 May 2015 16:32:25 +0800 Subject: [PATCH] add some tip in rules about non-unicode response --- rule_sample/rule__blank.js | 2 +- rule_sample/rule_replace_response_data.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/rule_sample/rule__blank.js b/rule_sample/rule__blank.js index 1aadb15..192ae2c 100644 --- a/rule_sample/rule__blank.js +++ b/rule_sample/rule__blank.js @@ -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); }, diff --git a/rule_sample/rule_replace_response_data.js b/rule_sample/rule_replace_response_data.js index c049ac6..a8ffbe2 100644 --- a/rule_sample/rule_replace_response_data.js +++ b/rule_sample/rule_replace_response_data.js @@ -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!";