The Python Oracle

Mitmproxy tampering with GET and POST request/ response in one script

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Quiet Intelligence

--

Chapters
00:00 Mitmproxy Tampering With Get And Post Request/ Response In One Script
01:18 Accepted Answer Score 10
01:34 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)