From eb1b94b78c5ba5ab503600d8c8533442afa0e4d5 Mon Sep 17 00:00:00 2001 From: ottomao Date: Mon, 17 Nov 2014 01:33:41 -0800 Subject: [PATCH] Updated What is rule file and how to write (markdown) --- What-is-rule-file-and-how-to-write.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/What-is-rule-file-and-how-to-write.md b/What-is-rule-file-and-how-to-write.md index 9075c44..424cd58 100644 --- a/What-is-rule-file-and-how-to-write.md +++ b/What-is-rule-file-and-how-to-write.md @@ -1,3 +1,6 @@ +What is rule file and how to write +============================== + Anyproxy exposes a lot of interface for you to hack requests. To use them, you have to write a *.js file which is a Node.js module. Here we name this kind of file as **rule file**, which means this file defines the rule to handle all requests. How it works @@ -65,8 +68,25 @@ module.exports = { }; ``` -[TODO] +* `summary` the summary of this rule file. AnyProxy will show it to user. +* `shouldInterceptHttpsReq` whether https request should be intercepted. If `false` is returned, https requests will not be decrpted. This is only available after certificated has been generated and configured. +* `shouldUseLocalResponse` whether you want to response this request with local data. If it returns true, `dealLocalResponse` will be called and other function about target server will be ignored. +* `dealLocalResponse` if `shouldUseLocalResponse` returns true, this function will be called, and you should use the ``callback`` function to provide statusCode, response header and response data. +* `replaceRequestProtocol` before sending request to real server, this function will be called to decide whether a new protocol should be used. For example, returning "http" for a https request means you will send this request with https. The argument `protocol` is the origin protocol of request. Leave it blank if not necessary. +* `replaceRequestOption` AnyProxy internally use ``require('http').request(option,[callback])`` to send request, and here is the ``option`` anyproxy will use. Return your own one when needed. Along with `replaceRequestProtocol`, it is rather easy for you to forward the request to any other server. Leave it blank if not necessary. Ref about `option` : [http://nodejs.org/api/http.html#http_http_request_options_callback](http://nodejs.org/api/http.html#http_http_request_options_callback) +* `replaceRequestData` get and replace user's request body +* `replaceResponseStatusCode` replace the status code of target server, and this status code will be sent to client +* `replaceResponseHeader` replace the response header of target server, and this response header will be sent to client +* `replaceServerResDataAsync` use `callback` to give your response data +* `pauseBeforeSendingResponse` pause time in ms before sending response to client. + + +TODO +1.phase +2.req + + To invoke a rule file ------------------------- -* in shell ``anyproxy --rule /path/to/ruleFile.js`` \ No newline at end of file +* in shell ``anyproxy --rule /path/to/ruleFile.js``