update post body recorder

This commit is contained in:
加里
2014-09-02 14:54:45 +08:00
parent e92bfe2ae8
commit 8ad15162fa
17 changed files with 163 additions and 266 deletions

View File

@@ -1,31 +1,27 @@
module.exports = {
/*
these functions are required
you may leave their bodies blank if necessary
these functions will overwrite the default ones, write your own when necessary.
*/
//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
shouldUseLocalResponse : function(req){
return false;
shouldUseLocalResponse : function(req,reqBody){
if(/hello/.test(reqBody.toString())){
return true;
}else{
return false;
}
},
//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,callback){
dealLocalResponse : function(req,reqBody,callback){
callback(200,{"content-type":"text/html"},reqBody);
//callback(statusCode,resHeader,responseData)
},
//req is user's request sent to the proxy server
// option is how the proxy server will send request to the real server. i.e. require("http").request(option,function(){...})
//you may return a customized option to replace the original option
replaceRequestOption : function(req,option){
var newOption = option;
return newOption;
},
//replace the request protocol when sending to the real server
//protocol : "http" or "https"
replaceRequestProtocol:function(req,protocol){
@@ -33,6 +29,24 @@ module.exports = {
return newProtocol;
},
//req is user's request sent to the proxy server
//option is how the proxy server will send request to the real server. i.e. require("http").request(option,function(){...})
//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
replaceRequestOption : function(req,option){
var newOption = option;
return newOption;
},
//replace the request body
replaceRequestData: function(req,data){
// console.log(data.toString().indexOf("alipay.acquire.order.precreate"));
// if(data.toString().indexOf("alipay.acquire.order.precreate") >= 0){
// req.needReplaceResponse = true;
// }
// return text;
},
//replace the statusCode before it's sent to the user
replaceResponseStatusCode: function(req,res,statusCode){
var newStatusCode = statusCode;