diff --git a/What-is-rule-file-and-how-to-write.md b/What-is-rule-file-and-how-to-write.md index e294dad..99dc974 100644 --- a/What-is-rule-file-and-how-to-write.md +++ b/What-is-rule-file-and-how-to-write.md @@ -70,17 +70,24 @@ These interface can be grouped into three phases * Phase 2 , deal request parameters before sending to target server * Phase 3 , after getting response from target server, deal it before sending to client +#### **Phase 0** * `summary` the summary of this rule file. AnyProxy will show it to user. -* **Phase 1** `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. -* **Phase 1** `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. -* **Phase 1** `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. -* **Phase 2** `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. -* **Phase 2** `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) -* **Phase 2** `replaceRequestData` get and replace user's request body -* **Phase 3** `replaceResponseStatusCode` replace the status code of target server, and this status code will be sent to client -* **Phase 3** `replaceResponseHeader` replace the response header of target server, and this response header will be sent to client -* **Phase 3** `replaceServerResDataAsync` use `callback` to give your response data -* **Phase 3** `pauseBeforeSendingResponse` pause time in ms before sending response to client. + +#### **Phase 1** +* `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. + +#### **Phase 2** +* `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 + +#### **Phase 3** +* `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