aboutsummaryrefslogtreecommitdiffstats
path: root/examples/stub.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/stub.py')
-rw-r--r--examples/stub.py50
1 files changed, 29 insertions, 21 deletions
diff --git a/examples/stub.py b/examples/stub.py
index a0f73538..e5b4a39a 100644
--- a/examples/stub.py
+++ b/examples/stub.py
@@ -1,79 +1,87 @@
+import mitmproxy
"""
This is a script stub, with definitions for all events.
"""
-def start(context):
+def start():
"""
- Called once on script startup, before any other events.
+ Called once on script startup before any other events
"""
- context.log("start")
+ mitmproxy.ctx.log("start")
-def clientconnect(context, root_layer):
+def configure(options):
+ """
+ Called once on script startup before any other events, and whenever options changes.
+ """
+ mitmproxy.ctx.log("configure")
+
+
+def clientconnect(root_layer):
"""
Called when a client initiates a connection to the proxy. Note that a
connection can correspond to multiple HTTP requests
"""
- context.log("clientconnect")
+ mitmproxy.ctx.log("clientconnect")
-def request(context, flow):
+def request(flow):
"""
Called when a client request has been received.
"""
- context.log("request")
+ mitmproxy.ctx.log("request")
-def serverconnect(context, server_conn):
+def serverconnect(server_conn):
"""
Called when the proxy initiates a connection to the target server. Note that a
connection can correspond to multiple HTTP requests
"""
- context.log("serverconnect")
+ mitmproxy.ctx.log("serverconnect")
-def responseheaders(context, flow):
+def responseheaders(flow):
"""
Called when the response headers for a server response have been received,
but the response body has not been processed yet. Can be used to tell mitmproxy
to stream the response.
"""
- context.log("responseheaders")
+ mitmproxy.ctx.log("responseheaders")
-def response(context, flow):
+def response(flow):
"""
Called when a server response has been received.
"""
- context.log("response")
+ mitmproxy.ctx.log("response")
-def error(context, flow):
+def error(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.
"""
- context.log("error")
+ mitmproxy.ctx.log("error")
-def serverdisconnect(context, server_conn):
+def serverdisconnect(server_conn):
"""
Called when the proxy closes the connection to the target server.
"""
- context.log("serverdisconnect")
+ mitmproxy.ctx.log("serverdisconnect")
-def clientdisconnect(context, root_layer):
+def clientdisconnect(root_layer):
"""
Called when a client disconnects from the proxy.
"""
- context.log("clientdisconnect")
+ mitmproxy.ctx.log("clientdisconnect")
-def done(context):
+def done():
"""
Called once on script shutdown, after any other events.
"""
- context.log("done")
+ mitmproxy.ctx.log("done")