From 89a58d7e303f00e4ed7572b60db6a2073804c4a1 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 5 Aug 2011 10:47:43 +1200 Subject: Start on scripting documentation and examples. --- doc-src/index.html | 4 ++-- doc-src/index.py | 2 +- doc-src/scripts.html | 48 +++++++++++++++++++++++++++++++++++-------- doc-src/scripts/examples.html | 4 ++++ doc-src/scripts/flows.html | 0 doc-src/scripts/index.py | 2 +- 6 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 doc-src/scripts/examples.html delete mode 100644 doc-src/scripts/flows.html (limited to 'doc-src') diff --git a/doc-src/index.html b/doc-src/index.html index 4638b091..cb331ab9 100644 --- a/doc-src/index.html +++ b/doc-src/index.html @@ -11,9 +11,9 @@
  • Anticache
  • Filter expressions
  • -
  • Scripting API
  • +
  • Scripts
  • SSL interception
  • diff --git a/doc-src/index.py b/doc-src/index.py index 05254234..34704f7e 100644 --- a/doc-src/index.py +++ b/doc-src/index.py @@ -75,7 +75,7 @@ pages = [ Page("sticky.html", "Sticky cookies and auth"), Page("anticache.html", "Anticache"), Page("filters.html", "Filter expressions"), - Page("scripts.html", "External scripts"), + Page("scripts.html", "Scripts"), Directory("scripts"), Page("ssl.html", "SSL interception"), Directory("certinstall"), diff --git a/doc-src/scripts.html b/doc-src/scripts.html index 2514923e..990ca070 100644 --- a/doc-src/scripts.html +++ b/doc-src/scripts.html @@ -1,14 +1,46 @@ -Both __mitmproxy__ and __mitmdump__ allow you to modify requests and responses -with external scripts. This is often done through the __--reqscript__ and -__--respscript__ options +__mitmproxy__ has a powerful event-drive scripting API, that allows you to +modify flows on-the-fly or rewrite previously saved flows locally. + + +## Events + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    start(ctx)Called once on startup, before any other events.
    clientconnect(ctx, ClientConnect)Called when a client initiates a connection to the proxy. Note that + a connection can correspond to multiple HTTP requests.
    request(ctx, Flow)Called when a client request has been received.
    response(ctx, Flow)Called when a server response has been received.
    error(ctx, Flow)Called when a flow error has occured, e.g. invalid server + responses, or interrupted connections. This is distinct from a valid + server HTTP error response, which is simply a response with an HTTP + error code.
    clientdisconnect(ctx, ClientDisconnect)Called when a client disconnects from the proxy.
    done(ctx)Called once on script shutdown, after any other events.
    -The script interface is simple - scripts simply read, -modify and return a single __libmproxy.flow.Flow__ object, using the methods -defined in the __libmproxy.script__ module. Scripts must be executable. - -!example("examples/simple_script")!$ diff --git a/doc-src/scripts/examples.html b/doc-src/scripts/examples.html new file mode 100644 index 00000000..bfa1f8d7 --- /dev/null +++ b/doc-src/scripts/examples.html @@ -0,0 +1,4 @@ + +## Stub script + +$!example("examples/stub.py")!$ diff --git a/doc-src/scripts/flows.html b/doc-src/scripts/flows.html deleted file mode 100644 index e69de29b..00000000 diff --git a/doc-src/scripts/index.py b/doc-src/scripts/index.py index 805a17d9..987cf840 100644 --- a/doc-src/scripts/index.py +++ b/doc-src/scripts/index.py @@ -1,6 +1,6 @@ from countershape import Page pages = [ - Page("flows.html", "Introduction to flows"), + Page("examples.html", "Examples"), Page("api.html", "API"), ] -- cgit v1.2.3