mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-07-07 00:30:34 +00:00
Updated What is rule file and how to write (markdown)
parent
eb1b94b78c
commit
1cd1ee7af2
@ -1,6 +1,3 @@
|
||||
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
|
||||
@ -68,22 +65,26 @@ module.exports = {
|
||||
};
|
||||
```
|
||||
|
||||
These interface can be grouped into three phases
|
||||
* Phase 1 , when proxy server gets request from client
|
||||
* Phase 2 , deal request parameters before sending to target server
|
||||
* Phase 3 , after getting response from target server, deal it before sending to client
|
||||
|
||||
* `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.
|
||||
* **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.
|
||||
|
||||
|
||||
TODO
|
||||
1.phase
|
||||
2.req
|
||||
req
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user