What is the equivalent of libmproxy in the new mitmproxy?

Finally, I upgraded my version of Python from version 2.7 to 3.6.1, and also upgraded mine mitmproxyfrom the old and good v0.16 to the newest version.

I worked with libmproxyto manipulate requests that were redirected through a proxy with this syntax:

from netlib.http import decoded
from libmproxy import controller, proxy
from libmproxy.proxy.server import ProxyServer

class StickyMaster(controller.Master):
    def __init__(self, server):
        controller.Master.__init__(self, server)
        self.stickyhosts = {}

    def run(self):
        try:
            return controller.Master.run(self)
        except KeyboardInterrupt:
            self.shutdown()

    def handle_request(self, flow):
        flow.reply()

    def handle_response(self, flow):
        with decoded(flow.response):
            <DO SOMETHING>
        flow.reply()

config = proxy.ProxyConfig(port=8081)
server = ProxyServer(config)
m = StickyMaster(server)
m.run()

I realized that the syntax in the new version is completely different, and I can not find the relevant documentation with an example of how to do this.

Can someone share an example of basic code with me, for example, I wrote above about the latest version?

+4
source share

Source: https://habr.com/ru/post/1675778/


All Articles