mitmproxy/examples/stub.py

80 lines
1.9 KiB
Python
Raw Normal View History

"""
This is a script stub, with definitions for all events.
"""
2015-05-30 00:03:28 +00:00
2016-06-14 01:17:09 +00:00
def start(context):
"""
Called once on script startup, before any other events.
"""
2014-09-08 14:02:31 +00:00
context.log("start")
2015-05-30 00:03:28 +00:00
2015-08-31 15:05:52 +00:00
def clientconnect(context, root_layer):
"""
Called when a client initiates a connection to the proxy. Note that a
connection can correspond to multiple HTTP requests
"""
2014-09-08 14:02:31 +00:00
context.log("clientconnect")
2015-05-30 00:03:28 +00:00
2015-09-03 22:46:42 +00:00
def request(context, flow):
"""
2015-09-03 22:46:42 +00:00
Called when a client request has been received.
"""
2015-09-03 22:46:42 +00:00
context.log("request")
2015-05-30 00:03:28 +00:00
2015-09-03 22:46:42 +00:00
def serverconnect(context, server_conn):
"""
2015-09-03 22:46:42 +00:00
Called when the proxy initiates a connection to the target server. Note that a
connection can correspond to multiple HTTP requests
"""
2015-09-03 22:46:42 +00:00
context.log("serverconnect")
2014-07-21 19:06:55 +00:00
2014-09-08 14:02:31 +00:00
def responseheaders(context, flow):
2014-07-21 19:06:55 +00:00
"""
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.
"""
2014-09-08 14:02:31 +00:00
context.log("responseheaders")
2014-07-21 19:06:55 +00:00
2015-05-30 00:03:28 +00:00
2014-09-08 14:02:31 +00:00
def response(context, flow):
"""
Called when a server response has been received.
"""
2014-09-08 14:02:31 +00:00
context.log("response")
2015-05-30 00:03:28 +00:00
2014-09-08 14:02:31 +00:00
def error(context, 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
2012-12-09 21:57:11 +00:00
response, which is simply a response with an HTTP error code.
"""
2014-09-08 14:02:31 +00:00
context.log("error")
2015-05-30 00:03:28 +00:00
2015-09-03 22:46:42 +00:00
def serverdisconnect(context, server_conn):
2015-08-31 15:05:52 +00:00
"""
Called when the proxy closes the connection to the target server.
"""
context.log("serverdisconnect")
def clientdisconnect(context, root_layer):
"""
Called when a client disconnects from the proxy.
"""
2014-09-08 14:02:31 +00:00
context.log("clientdisconnect")
2015-05-30 00:03:28 +00:00
2014-09-08 14:02:31 +00:00
def done(context):
"""
Called once on script shutdown, after any other events.
"""
2014-09-08 14:02:31 +00:00
context.log("done")