mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-07-07 16:49:30 +00:00
Updated What is rule file and how to write (markdown)
parent
a444d8eb77
commit
eb1b94b78c
@ -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.
|
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
|
How it works
|
||||||
@ -65,7 +68,24 @@ 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
|
To invoke a rule file
|
||||||
-------------------------
|
-------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user