/* read the following wiki before using rule file https://github.com/alibaba/anyproxy/wiki/What-is-rule-file-and-how-to-write-one */ module.exports = { /* These functions will overwrite the default ones, write your own when necessary. Comments in Chinese are nothing but a translation of key points. Be relax if you dont understand. 致中文用戶:中文注釋都是只摘要,必要時請參閱英文文檔。歡迎提出修改建議。 */ summary:function(){ return"this is a blank rule for AnyProxy"; },
//======================= //whengetting a requestfromuser //收到用戶請求之后 //=======================
//是否截獲https請求 //should intercept https request,orit will be forwardedtorealserver shouldInterceptHttpsReq :function(req){ returnfalse; },
//是否在本地直接發送響應(不再向服務器發出請求) //whethertointercept this requestbylocallogic //if thereturnvalueistrue, anyproxy will call dealLocalResponsetoget response dataandwillnotsend requesttoremote server anymore //reqistheuser's request sent to the proxy server shouldUseLocalResponse : function(req,reqBody){ return false; },
//如果shouldUseLocalResponse返回true,會調用這個函數來獲取本地響應內容 //you may deal the response locally instead of sending it to server //this function be called when shouldUseLocalResponse returns true //callback(statusCode,resHeader,responseData) //e.g. callback(200,{"content-type":"text/html"},"hello world") dealLocalResponse : function(req,reqBody,callback){ callback(statusCode,resHeader,responseData) },
//======================= //when ready to send a request to server //向服務端發出請求之前 //=======================
//替換向服務器發出的請求協議(http和https的替換) //replace the request protocol when sending to the real server //protocol : "http" or "https" replaceRequestProtocol:function(req,protocol){ var newProtocol = protocol; return newProtocol; },
//替換向服務器發出的請求參數(option) //option is the configuration of the http request sent to remote server. You may refers tohttps://nodejs.org/api/http.html //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; },
//替換請求的body //replace the request body replaceRequestData: function(req,data){ return data; },
//======================= //when ready to send the response to user after receiving response from server //向用戶返回服務端的響應之前 //=======================
//替換服務器響應的http狀態碼 //replace the statusCode before it's senttotheuser replaceResponseStatusCode:function(req,res,statusCode){ var newStatusCode = statusCode; returnnewStatusCode; },
//替換服務器響應的http頭 //replacethe httpHeader before it's sent to the user //Here header == res.headers replaceResponseHeader: function(req,res,header){ var newHeader = header; return newHeader; },
//替換服務器響應的數據 //replace the response from the server before it's senttotheuser //you mayreturneither a Bufferora string //serverResDataisa Buffer.forthose non-unicode reponse , serverResData.toString() shouldnotbe yourfirstchoice. replaceServerResDataAsync:function(req,res,serverResData,callback){ callback(serverResData); },