diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f76f798 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +.*.swp +._* +.DS_Store +.git +.hg +.lock-wscript +.svn +.wafpickle-* +CVS +npm-debug.log +logs +*.log +pids +*.pid +*.seed +lib-cov +coverage +.grunt +build/Release +node_modules +.lock-wscript \ No newline at end of file diff --git a/cn/index.html b/cn/index.html new file mode 100644 index 0000000..88a0bb0 --- /dev/null +++ b/cn/index.html @@ -0,0 +1,248 @@ + +
+
+
+//append "hello world" to all web pages
+//file : rule_replace_response_data.js
+//run : anyproxy --rule rule_replace_response_data.js
+module.exports = {
+ replaceServerResDataAsync: function(req,res,serverRes,cb){
+
+ if(/html/i.test(res.headers['content-type'])){
+ var newDataStr = serverRes.toString();
+ newDataStr += "hello world!";
+ cb(newDataStr);
+ }
+ }
+};
+
+
+
+
+
+//remove cache related header
+//file : rule_remove_cache_header.js
+//run : anyproxy --rule rule_remove_cache_header.js
+module.exports = {
+ replaceRequestOption : function(req,option){
+ var newOption = option;
+ delete newOption.headers['if-modified-since'];
+
+ return newOption;
+ }
+};
+
+
+
+
+
+//assign a specific IP adress for some request
+//file : rule_reverse_proxy.js
+//run : anyproxy --rule anyproxy --rule rule_reverse_proxy.js
+module.exports = {
+ replaceRequestOption : function(req,option){
+ var newOption = option;
+ if(newOption.headers.host == "www.taobao.com"){
+ newOption.hostname = "192.168.1.3";
+ newOption.port = "80";
+ }
+
+ return newOption;
+ }
+};
+
+
+
+
+
+//replace all the images with local one
+//file : rule_use_local_data.js
+//run : anyproxy --rule anyproxy --rule rule_use_local_data.js
+var fs = require("fs"),
+ img = fs.readFileSync("sample.jpg");
+
+module.exports = {
+ shouldUseLocalResponse : function(req,reqBody){
+ if(/\.(png|gif|jpg|jpeg)$/.test(req.url)){
+ req.replaceLocalFile = true;
+ return true;
+ }else{
+ return false;
+ }
+ },
+
+ dealLocalResponse : function(req,reqBody,callback){
+ if(req.replaceLocalFile){
+ callback(200, {"content-type":"image/png"},img );
+ }
+ }
+};
+
+
+
+ anyproxy
+
+//append "hello world" to all web pages
+//file : rule_replace_response_data.js
+//run : anyproxy --rule rule_replace_response_data.js
+module.exports = {
+ replaceServerResDataAsync: function(req,res,serverRes,cb){
+
+ if(/html/i.test(res.headers['content-type'])){
+ var newDataStr = serverRes.toString();
+ newDataStr += "hello world!";
+ cb(newDataStr);
+ }
+ }
+};
+
+
+
+
+
+//remove cache related header
+//file : rule_remove_cache_header.js
+//run : anyproxy --rule rule_remove_cache_header.js
+module.exports = {
+ replaceRequestOption : function(req,option){
+ var newOption = option;
+ delete newOption.headers['if-modified-since'];
+
+ return newOption;
+ }
+};
+
+
+
+
+
+//assign a specific IP adress for some request
+//file : rule_reverse_proxy.js
+//run : anyproxy --rule anyproxy --rule rule_reverse_proxy.js
+module.exports = {
+ replaceRequestOption : function(req,option){
+ var newOption = option;
+ if(newOption.headers.host == "www.taobao.com"){
+ newOption.hostname = "192.168.1.3";
+ newOption.port = "80";
+ }
+
+ return newOption;
+ }
+};
+
+
+
+
+
+//replace all the images with local one
+//file : rule_use_local_data.js
+//run : anyproxy --rule anyproxy --rule rule_use_local_data.js
+var fs = require("fs"),
+ img = fs.readFileSync("sample.jpg");
+
+module.exports = {
+ shouldUseLocalResponse : function(req,reqBody){
+ if(/\.(png|gif|jpg|jpeg)$/.test(req.url)){
+ req.replaceLocalFile = true;
+ return true;
+ }else{
+ return false;
+ }
+ },
+
+ dealLocalResponse : function(req,reqBody,callback){
+ if(req.replaceLocalFile){
+ callback(200, {"content-type":"image/png"},img );
+ }
+ }
+};
+
+
+
+ npm install -g anyproxy
, 可能需要sudo
npm install -g anyproxy
, may requiresudo
anyproxy
anyproxy
//append "hello world" to all web pages
@@ -111,7 +120,7 @@ module.exports = {
//remove cache related header
@@ -134,7 +143,7 @@ module.exports = {
//assign a specific IP adress for some request
@@ -160,7 +169,7 @@ module.exports = {
//replace all the images with local one
@@ -193,7 +202,7 @@ module.exports = {
npm install -g anyproxy
, ${installationStepB}sudo
anyproxy
+
+//append "hello world" to all web pages
+//file : rule_replace_response_data.js
+//run : anyproxy --rule rule_replace_response_data.js
+module.exports = {
+ replaceServerResDataAsync: function(req,res,serverRes,cb){
+
+ if(/html/i.test(res.headers['content-type'])){
+ var newDataStr = serverRes.toString();
+ newDataStr += "hello world!";
+ cb(newDataStr);
+ }
+ }
+};
+
+
+
+
+
+//remove cache related header
+//file : rule_remove_cache_header.js
+//run : anyproxy --rule rule_remove_cache_header.js
+module.exports = {
+ replaceRequestOption : function(req,option){
+ var newOption = option;
+ delete newOption.headers['if-modified-since'];
+
+ return newOption;
+ }
+};
+
+
+
+
+
+//assign a specific IP adress for some request
+//file : rule_reverse_proxy.js
+//run : anyproxy --rule anyproxy --rule rule_reverse_proxy.js
+module.exports = {
+ replaceRequestOption : function(req,option){
+ var newOption = option;
+ if(newOption.headers.host == "www.taobao.com"){
+ newOption.hostname = "192.168.1.3";
+ newOption.port = "80";
+ }
+
+ return newOption;
+ }
+};
+
+
+
+
+
+//replace all the images with local one
+//file : rule_use_local_data.js
+//run : anyproxy --rule anyproxy --rule rule_use_local_data.js
+var fs = require("fs"),
+ img = fs.readFileSync("sample.jpg");
+
+module.exports = {
+ shouldUseLocalResponse : function(req,reqBody){
+ if(/\.(png|gif|jpg|jpeg)$/.test(req.url)){
+ req.replaceLocalFile = true;
+ return true;
+ }else{
+ return false;
+ }
+ },
+
+ dealLocalResponse : function(req,reqBody,callback){
+ if(req.replaceLocalFile){
+ callback(200, {"content-type":"image/png"},img );
+ }
+ }
+};
+
+
+
+