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. --- examples/add_header.py | 2 -- examples/stub.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 examples/stub.py (limited to 'examples') diff --git a/examples/add_header.py b/examples/add_header.py index dab33c8c..6ddeab3d 100644 --- a/examples/add_header.py +++ b/examples/add_header.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python """ This script adds a new header to all responses. """ -from libmproxy import script def response(ctx, f): f.response.headers["newheader"] = ["foo"] diff --git a/examples/stub.py b/examples/stub.py new file mode 100644 index 00000000..f235ea85 --- /dev/null +++ b/examples/stub.py @@ -0,0 +1,47 @@ +""" + This is a script stub, with empty definitions for all events. +""" + +def start(ctx): + """ + Called once on script startup, before any other events. + """ + pass + +def clientconnect(ctx, client_connect): + """ + Called when a client initiates a connection to the proxy. Note that a + connection can correspond to multiple HTTP requests + """ + pass + +def request(ctx, flow): + """ + Called when a client request has been received. + """ + +def response(ctx, flow): + """ + Called when a server response has been received. + """ + pass + +def 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. + """ + pass + +def clientdisconnect(ctx, client_disconnect): + """ + Called when a client disconnects from the proxy. + """ + pass + +def done(ctx): + """ + Called once on script shutdown, after any other events. + """ + pass -- cgit v1.2.3