Moving to mitmproxy 3 as a module

Hi,

I’m using mitmporxy module in my project just like in flowbasic.py example from mitmproxy 2.x. So in short it was like this (in my case I start a thread and I communicate with another process and send some XML files that I need to check):

class MyMaster(master.Master):
    def run(self):
        try:
            master.Master.run(self)
        except KeyboardInterrupt:
            self.shutdown()
    [..]
    @controller.handler
    def response(self, f):
        DO_MY_STUFF(f)
    [..]


opts = options.Options(cadir="~/.mitmproxy/")
config = ProxyConfig(opts)
server = ProxyServer(config)
m = MyMaster(opts, server)
m.run()

For the version 3 there is no example flowbasic.py and reading the docs and checking the source won’t give me a clue how to put response function.

Do anyone have such flowbasic.py for v3 prepared or some ideas?

Hi,

subclassing master.Master is deprecated for quite a while now. :wink: You should be able to achieve your task by writing a mitmproxy addon, see here: https://docs.mitmproxy.org/stable/addons-overview/

ok… But I need to make it as a class in the same file (so I can provide parameters - multiprocess queue). I have tried but until now - without luck :frowning:

I’m getting only the running and done events to happen. How to make it properly to get the response event working ?