From 20d402fd1b13cc9294bde4089180b08e6a9b1e03 Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:21:18 +0000 Subject: [PATCH] Optionally encode response bodies --- tests/mitmproxy_addons/callback.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/mitmproxy_addons/callback.py b/tests/mitmproxy_addons/callback.py index d2339c8..03e1516 100644 --- a/tests/mitmproxy_addons/callback.py +++ b/tests/mitmproxy_addons/callback.py @@ -63,17 +63,21 @@ def response(self, flow): if self.config["callback_url"] == "": return # ignore responses if we aren't told a url if flowfilter.match(self.filter, flow): - try: + try: # e.g GET requests have no req body req_body = flow.request.json() except: req_body = None + try: # e.g OPTIONS responses have no res body + res_body = flow.response.json() + except: + res_body = None data = json.dumps({ "method": flow.request.method, "access_token": flow.request.headers.get("Authorization", "").removeprefix("Bearer "), "url": flow.request.url, "response_code": flow.response.status_code, "request_body": req_body, - "response_body": flow.response.json(), + "response_body": res_body, }) request = Request( self.config["callback_url"],