Created
May 31, 2017 06:27
-
-
Save huyphan/0ea6bb022b161ec0ed20323bf9afad22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Generating Python script that replays HTTP requests captured by mitmproxy/mitmdump. | |
Usage: | |
$ mitmdump -s /tmp/replay_script_generator.py 2>&1 >/dev/null | |
''' | |
import pprint | |
import sys | |
pp = pprint.PrettyPrinter(indent=4) | |
REPLAY_SCRIPT = """ | |
method="{method}" | |
url="{url}" | |
headers={headers} | |
cookies={cookies} | |
data={data} | |
requests.request(method, url, headers=headers, cookies=cookies, data=data) | |
""" | |
def response(flow): | |
headers = flow.request.headers | |
headers_dict = {} | |
for header in headers: | |
if 'cookie' != header.lower(): | |
headers_dict[header] = headers[header] | |
cookies = dict(flow.request.cookies) | |
data = flow.request.content | |
params = { | |
'method': flow.request.method, | |
'url': flow.request.url, | |
'headers': pp.pformat(headers_dict), | |
'cookies': pp.pformat(cookies), | |
'data': repr(data) | |
} | |
print(REPLAY_SCRIPT.format(**params), file=sys.stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment