Mitmproxy tampering with GET and POST request/ response in one script
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Drifting Through My Dreams
--
Chapters
00:00 Question
01:57 Accepted answer (Score 10)
02:18 Thank you
--
Full question
https://stackoverflow.com/questions/2988...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #regex #proxy #mitmproxy #inlinescripting
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Drifting Through My Dreams
--
Chapters
00:00 Question
01:57 Accepted answer (Score 10)
02:18 Thank you
--
Full question
https://stackoverflow.com/questions/2988...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #regex #proxy #mitmproxy #inlinescripting
#avk47
ACCEPTED ANSWER
Score 10
The script you posted and Python's JSON module should get you pretty far:
def response(context, flow):
if flow.request.url == "...": # optionally filter based on some criteria...
with decoded(flow.response): # automatically decode gzipped responses.
data = json.loads(flow.response.content)
data["foo"] = "bar"
flow.response.content = json.dumps(data)