MacPaw Tech Blog — Hackathon Edition

Mitmproxy as an mock server

Announcement by: Aleksnadr Voloshchenko

I use mitmproxy on every occasion, but here is my top 5 use-cases:

  • Mock server. As in the example I usually mock APIs that are under development so I can test Setapp even if API is not ready yet. Another way is to mock negative cases which are hard to reproduce on native environment.
  • Sniffer. I use it to look through request-responses, to test analytics, or just when I’m curious what app sends here and there.
  • Man-in-the-middle. Updates request/response/headers/status codes with scripts or in app by regular expression
  • Intercept. mitm can intercept requests/responses by regex. I use it to pause some requests, change something and proceed. Also, Intercept is a very good tool if you want to test Timeouts of certain endpoints but not all of them.
  • Time profiler. You can use mitmproxy as a time profiler of request/response rate.
  • One more advantage of mitmproxy is that it detects changes of scripts on the go, so you don’t need to restart everything if you changed something.

    Here are a few easy steps to use mitmproxy:

  • Create Python extension
  • Launch mitmproxy with param
  • Enjoy
  • More at http://docs.mitmproxy.org