Skip to main content

Tech blog3 min read

Inspecting and Modifying HTTPS Traffic With mitmproxy

Pere PagesSoftware Engineer
A man-in-the-middle proxy intercepting encrypted traffic between two devices through a central magnifying inspection point ringed by padlocks

When you need to inspect, modify, or replay HTTP(S) traffic, few tools are as powerful and flexible as mitmproxy.
It's open-source, scriptable in Python, and works seamlessly as a man-in-the-middle proxy.


🚀 What Is mitmproxy?

mitmproxy is an interactive HTTPS proxy that lets you:

  • Inspect requests/responses in real time
  • Intercept and modify traffic on the fly
  • Replay, record, or craft custom flows
  • Run in terminal, web UI, or as a headless server

It acts as a transparent layer between the client and the server, giving you full control over the network.


🧠 Why You Should Use It

1. Debug Any Client​

Works with browsers, mobile devices, CLI tools, or backend services. Just set it as the proxy → instantly view traffic.

2. Full HTTPS Interception​

Install the mitmproxy CA cert on your device and decrypt SSL traffic easily. Perfect for debugging encrypted APIs.

3. Modify Responses On the Fly​

Rewrite headers, JSON payloads, or entire responses interactively. Great for:

  • Mocking backend features
  • Testing error scenarios
  • Speeding up frontend development without changing backend code

4. Automate with Python​

Use mitmproxy add-ons to script complex behaviors:

PYTHON
# example: force 500 errors for specific endpoints
def response(flow):
if "/api/test" in flow.request.pretty_url:
flow.response.status_code = 500

5. Record & Replay Traffic​

Capture sessions once and replay them repeatedly — ideal for load testing, regression testing, or demos.

6. Open Source & Lightweight​

No telemetry, no vendor lock-in. Runs locally, integrates easily into dev environments and CI setups.


🧪 Common Use Cases

  • Debugging mobile apps without modifying them
  • Overwriting API responses for local development
  • Inspecting browser network traffic in depth
  • Testing error handling in frontend apps
  • Capturing traffic from IoT devices

⚡ Quick Start

BASH
brew install mitmproxy # macOS
mitmproxy # start interactive proxy on :8080

Then set your browser or device to use http://localhost:8080 as HTTP/HTTPS proxy and install the CA certificate from http://mitm.it.


📝 Final Thoughts

mitmproxy is like a debugger for the network layer. Whether you’re a frontend dev, backend engineer, or security tester, it gives you total visibility and control over HTTP(S) traffic — without relying on external services.

👉 mitmproxy.org

💡 Tip: Pair mitmproxy with your browser devtools or mobile simulator for rapid iteration and powerful debugging.

References