From 66b3b86a1263e7feccc824b7319109c8f1aa691d Mon Sep 17 00:00:00 2001 From: OttoMao Date: Wed, 20 May 2015 16:32:25 +0800 Subject: [PATCH 1/3] 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!"; From 283ffde6f94e93f7ba9d2cd0ecd64e416ab67668 Mon Sep 17 00:00:00 2001 From: OttoMao Date: Mon, 1 Jun 2015 11:23:19 +0800 Subject: [PATCH 2/3] correct typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 122e74d..52602f9 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ var options = { webConfigPort : 8088, // optional, internal port for web config(beta), replace this when it is conflict with your own service throttle : 10, // optional, speed limit in kb/s disableWebInterface : false, //optional, set it when you don't want to use the web interface - silent : false, //optional, do not print anything into terminal. do not set it when you are still debugging. + silent : false //optional, do not print anything into terminal. do not set it when you are still debugging. }; new proxy.proxyServer(options); From 450c72b47b7524b22382362da6d54cb8139ab7cb Mon Sep 17 00:00:00 2001 From: OttoMao Date: Mon, 8 Jun 2015 09:45:22 +0800 Subject: [PATCH 3/3] fix a bug when there is an error with rule.js --- proxy.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/proxy.js b/proxy.js index 3473e0e..e81edd5 100644 --- a/proxy.js +++ b/proxy.js @@ -49,12 +49,7 @@ try{ if(fs.existsSync(path.join(process.cwd(),'rule.js'))){ default_rule = require(path.join(process.cwd(),'rule')); } -}catch(e){ - if(e){ - logUtil.printLog("error" + e, logUtil.T_ERR); - throw e; - } -} +}catch(e){} //option //option.type : 'http'(default) or 'https'