|
1 | 1 |
|
2 | | -Both __mitmproxy__ and __mitmdump__ allow you to modify requests and responses |
3 | | -with external scripts. This is often done through the __--reqscript__ and |
4 | | -__--respscript__ options |
| 2 | +__mitmproxy__ has a powerful event-drive scripting API, that allows you to |
| 3 | +modify flows on-the-fly or rewrite previously saved flows locally. |
| 4 | + |
| 5 | + |
| 6 | +## Events |
| 7 | + |
| 8 | +<table> |
| 9 | + <tr> |
| 10 | + <td>start(ctx)</td> |
| 11 | + <td>Called once on startup, before any other events.</td> |
| 12 | + </tr> |
| 13 | + <tr> |
| 14 | + <td>clientconnect(ctx, ClientConnect)</td> |
| 15 | + <td>Called when a client initiates a connection to the proxy. Note that |
| 16 | + a connection can correspond to multiple HTTP requests.</td> |
| 17 | + </tr> |
| 18 | + <tr> |
| 19 | + <td>request(ctx, Flow)</td> |
| 20 | + <td>Called when a client request has been received.</td> |
| 21 | + </tr> |
| 22 | + <tr> |
| 23 | + <td>response(ctx, Flow)</td> |
| 24 | + <td>Called when a server response has been received.</td> |
| 25 | + </tr> |
| 26 | + <tr> |
| 27 | + <td>error(ctx, Flow)</td> |
| 28 | + <td>Called when a flow error has occured, e.g. invalid server |
| 29 | + responses, or interrupted connections. This is distinct from a valid |
| 30 | + server HTTP error response, which is simply a response with an HTTP |
| 31 | + error code. </td> |
| 32 | + </tr> |
| 33 | + <tr> |
| 34 | + <td>clientdisconnect(ctx, ClientDisconnect)</td> |
| 35 | + <td>Called when a client disconnects from the proxy.</td> |
| 36 | + </tr> |
| 37 | + <tr> |
| 38 | + <td>done(ctx)</td> |
| 39 | + <td>Called once on script shutdown, after any other events.</td> |
| 40 | + </tr> |
| 41 | +</table> |
5 | 42 |
|
6 | 43 |
|
7 | | -The script interface is simple - scripts simply read, |
8 | | -modify and return a single __libmproxy.flow.Flow__ object, using the methods |
9 | | -defined in the __libmproxy.script__ module. Scripts must be executable. |
10 | | - |
11 | | -!example("examples/simple_script")!$ |
12 | 44 |
|
13 | 45 |
|
14 | 46 |
|
|
0 commit comments