From 64658975d89216b9a6940b12393f55da844a8607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=A0=E9=87=8C?= Date: Tue, 21 Oct 2014 14:49:13 +0800 Subject: [PATCH] update doc --- README.md | 2 +- rule_sample/rule__blank.js | 18 ++++-------------- rule_sample/rule_use_local_data.js | 4 ++++ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2c9e749..ae5a96b 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Rule module * 改变服务端响应的http状态码 * **[rule_use_local_data.js](./rule_sample/rule_use_local_data.js)** * map some requests to local file - * 把响应映射到本地 + * 把图片响应映射到本地 * and here is the scheme in rule module diff --git a/rule_sample/rule__blank.js b/rule_sample/rule__blank.js index 3e87c76..1825a1f 100644 --- a/rule_sample/rule__blank.js +++ b/rule_sample/rule__blank.js @@ -11,8 +11,6 @@ module.exports = { - - //======================= //when getting a request from user //收到用户请求之后 @@ -21,6 +19,7 @@ module.exports = { //是否在本地直接发送响应(不再向服务器发出请求) //whether to intercept this request by local logic //if the return value is true, anyproxy will call dealLocalResponse to get response data and will not send request to remote server anymore + //req is the user's request sent to the proxy server shouldUseLocalResponse : function(req,reqBody){ return false; }, @@ -36,10 +35,6 @@ module.exports = { - - - - //======================= //when ready to send a request to server //向服务端发出请求之前 @@ -54,9 +49,9 @@ module.exports = { }, //替换向服务器发出的请求参数(option) - //req is user's request which will be sent to the proxy server, docs : http://nodejs.org/api/http.html#http_http_request_options_callback - //you may return a customized option to replace the original option - //you should not write content-length header in options, since anyproxy will handle it for you + //option is the configuration of the http request sent to remote server. You may refers to http://nodejs.org/api/http.html#http_http_request_options_callback + //you may return a customized option to replace the original one + //you should not overwrite content-length header in options, since anyproxy will handle it for you replaceRequestOption : function(req,option){ var newOption = option; return newOption; @@ -70,8 +65,6 @@ module.exports = { - - //======================= //when ready to send the response to user after receiving response from server //向用户返回服务端的响应之前 @@ -114,9 +107,6 @@ module.exports = { - - - //======================= //https config //======================= diff --git a/rule_sample/rule_use_local_data.js b/rule_sample/rule_use_local_data.js index ddf2a77..f560f6d 100644 --- a/rule_sample/rule_use_local_data.js +++ b/rule_sample/rule_use_local_data.js @@ -5,6 +5,10 @@ var LOCAL_IMAGE = "/Users/path/to/image.png"; module.exports = { + summary:function(){ + return "replace all the images with local one"; + }, + //mark if use local response shouldUseLocalResponse : function(req,reqBody){ if(/\.(png|gif|jpg|jpeg)$/.test(req.url)){