Skip to content

Instantly share code, notes, and snippets.

@dol
Last active November 29, 2016 14:20
Show Gist options
  • Save dol/5721334 to your computer and use it in GitHub Desktop.
Save dol/5721334 to your computer and use it in GitHub Desktop.
Store mitmdump raw requests and responses instead of internal format
# Print flow request in raw format. This can be used to record request fixtures
import datetime
import os
def response(context, flow):
timestr = datetime.datetime.utcnow().strftime('%Y%m%d-%H%M%S-%f')
with open('tmp/raw-%s.mitm' % timestr, "a") as f:
f.write("-------------- REQUEST START --------------\n")
f.write(flow.request._assemble())
f.write("\n-------------- REQUEST END --------------\n")
if "MITMPROXY_RESPONSE" in os.environ:
f.write("-------------- RESPONSE START --------------\n")
f.write(flow.response._assemble())
f.write("\n-------------- RESPONSE END --------------\n")
#!/usr/bin/env sh
# Note: Start script with 'MITMPROXY_RESPONSE=1 ./start_mitmproxy.sh' to enable response capturing
mitmdump -s raw_dump.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment