mitmproxy/examples/flowbasic

44 lines
1.0 KiB
Plaintext
Raw Normal View History

2011-08-13 01:51:38 +00:00
#!/usr/bin/env python
"""
This example shows how to build a proxy based on mitmproxy's Flow
primitives.
Heads Up: In the majority of cases, you want to use inline scripts.
Note that request and response messages are not automatically replied to,
so we need to implement handlers to do this.
2011-08-13 01:51:38 +00:00
"""
from mitmproxy import flow, controller, options
from mitmproxy.proxy import ProxyServer, ProxyConfig
2011-08-13 01:51:38 +00:00
2014-09-08 14:02:31 +00:00
2011-08-13 01:51:38 +00:00
class MyMaster(flow.FlowMaster):
def run(self):
try:
flow.FlowMaster.run(self)
except KeyboardInterrupt:
self.shutdown()
2016-05-29 00:54:52 +00:00
@controller.handler
def request(self, f):
print("request", f)
2011-08-13 01:51:38 +00:00
2016-05-29 00:54:52 +00:00
@controller.handler
def response(self, f):
print("response", f)
2011-08-13 01:51:38 +00:00
@controller.handler
def error(self, f):
print("error", f)
@controller.handler
def log(self, f):
print("log", f)
2011-08-13 01:51:38 +00:00
opts = options.Options(cadir="~/.mitmproxy/")
config = ProxyConfig(opts)
2011-08-13 01:51:38 +00:00
state = flow.State()
server = ProxyServer(config)
m = MyMaster(opts, server, state)
2011-08-13 01:51:38 +00:00
m.run()